0

I'm a newbee Ceph developer, and recenlty reading code of snapshots. From pg_pool_t::add_unmanaged_snap, it's obvious that the first RBD snapshot id should start from 2, but in reality, it starts from 4, I wonder whether there are some organisms in RBD snap, which increments snap_seq, could anyone help me?

Thanks in advance!

Below is the code of pg_pool_t::add_unmanaged_snap.

void pg_pool_t::add_unmanaged_snap(uint64_t& snapid)
{
  ceph_assert(!is_pool_snaps_mode());
  if (snap_seq == 0) {
    // kludge for pre-mimic tracking of pool vs selfmanaged snaps.  after
    // mimic this field is not decoded but our flag is set; pre-mimic, we
    // have a non-empty removed_snaps to signifiy a non-pool-snaps pool.
    removed_snaps.insert(snapid_t(1));
    snap_seq = 1;
  }
  flags |= FLAG_SELFMANAGED_SNAPS;
  snapid = snap_seq = snap_seq + 1;
}

Following screenshot is the process of rbd snapshot creation on a totally new rbd pool. Obviously, snapshot id here starts from 4

rbd snapshot creation on a totally new rbd pool

enter image description here

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
ghost
  • 41
  • 3
  • Can you show where you saw that it starts with 4? Did you already create and remove snapshots? – eblock Apr 19 '21 at 07:41
  • @eblock Yes, I've created snapshots in new rbd pool, and snap id starts from 4. Later I'll update a screenshot of rbd snap creation – ghost Apr 19 '21 at 08:30
  • No I mean did you create and delete snapshots before looking into the snap_id? Or was it a fresh pool with brand new snapshots? – eblock Apr 19 '21 at 10:00
  • @eblock It was a fresh pool with brand new snapshots, I've uploaded the whole process of creating new rbd pool and creating snapshots, maybe you could check in the figure – ghost Apr 20 '21 at 10:40
  • You are right, I could reproduce it. If you run `ceph osd pool ls detail` you will see that the pool already has a `removed snaps` entry: `pool 4 'iscsi-images' replicated size 3 min_size 2 crush_rule 0 object_hash rjenkins pg_num 128 pgp_num 128 last_change 166 flags hashpspool stripe_width 0 application rbd removed_snaps [1~3]` But I don't know why there are already 3 removed snaps, to be honest. As soon as you create the rbd image there are 3 removed snapshots visible. I've never thought about that. – eblock Apr 20 '21 at 10:59
  • @eblock I wonder maybe there's some initialization process for ceph to create and delete a snapshot itself. Well, from the code I post, you could know that the first snapshot id should be 2. ```if (snap_seq == 0) snap_seq = 1; snapid = snap_seq = snap_seq + 1;``` Also, from the code of ```pg_pool_t::remove_unmanaged_snap()```, we could know that snap_seq++ in removing process. So I guess that first ceph create a snap, snap_seq = 0 -> 1 -> 2, and remove it , snap_seq = 2 -> 3. When we create our own snap, snap_seq = 3 -> 4 – ghost Apr 22 '21 at 00:12

0 Answers0