1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef CEPH_MDS_ESLAVEUPDATE_H
16 #define CEPH_MDS_ESLAVEUPDATE_H
18 #include <string_view>
20 #include "../LogEvent.h"
21 #include "EMetaBlob.h"
24 * rollback records, for remote/slave updates, which may need to be manually
25 * rolled back during journal replay. (or while active if master fails, but in
26 * that case these records aren't needed.)
28 struct link_rollback
{
33 utime_t old_dir_mtime
;
34 utime_t old_dir_rctime
;
37 link_rollback() : ino(0), was_inc(false) {}
39 void encode(bufferlist
& bl
) const;
40 void decode(bufferlist::const_iterator
& bl
);
41 void dump(Formatter
*f
) const;
42 static void generate_test_instances(list
<link_rollback
*>& ls
);
44 WRITE_CLASS_ENCODER(link_rollback
)
47 * this is only used on an empty dir with a dirfrag on a remote node.
48 * we are auth for nothing. all we need to do is relink the directory
49 * in the hierarchy properly during replay to avoid breaking the
52 struct rmdir_rollback
{
60 void encode(bufferlist
& bl
) const;
61 void decode(bufferlist::const_iterator
& bl
);
62 void dump(Formatter
*f
) const;
63 static void generate_test_instances(list
<rmdir_rollback
*>& ls
);
65 WRITE_CLASS_ENCODER(rmdir_rollback
)
67 struct rename_rollback
{
70 utime_t dirfrag_old_mtime
;
71 utime_t dirfrag_old_rctime
;
72 inodeno_t ino
, remote_ino
;
77 drec() : remote_d_type((char)S_IFREG
) {}
79 void encode(bufferlist
& bl
) const;
80 void decode(bufferlist::const_iterator
& bl
);
81 void dump(Formatter
*f
) const;
82 static void generate_test_instances(list
<drec
*>& ls
);
84 WRITE_CLASS_MEMBER_ENCODER(drec
)
87 drec orig_src
, orig_dest
;
88 drec stray
; // we know this is null, but we want dname, old mtime/rctime
90 bufferlist srci_snapbl
;
91 bufferlist desti_snapbl
;
93 void encode(bufferlist
& bl
) const;
94 void decode(bufferlist::const_iterator
& bl
);
95 void dump(Formatter
*f
) const;
96 static void generate_test_instances(list
<rename_rollback
*>& ls
);
98 WRITE_CLASS_ENCODER(rename_rollback::drec
)
99 WRITE_CLASS_ENCODER(rename_rollback
)
102 class ESlaveUpdate
: public LogEvent
{
104 const static int OP_PREPARE
= 1;
105 const static int OP_COMMIT
= 2;
106 const static int OP_ROLLBACK
= 3;
108 const static int LINK
= 1;
109 const static int RENAME
= 2;
110 const static int RMDIR
= 3;
113 * we journal a rollback metablob that contains the unmodified metadata
114 * too, because we may be updating previously dirty metadata, which
115 * will allow old log segments to be trimmed. if we end of rolling back,
116 * those updates could be lost.. so we re-journal the unmodified metadata,
117 * and replay will apply _either_ commit or rollback.
124 __u8 op
; // prepare, commit, abort
125 __u8 origop
; // link | rename
127 ESlaveUpdate() : LogEvent(EVENT_SLAVEUPDATE
), master(0), op(0), origop(0) { }
128 ESlaveUpdate(MDLog
*mdlog
, std::string_view s
, metareqid_t ri
, int mastermds
, int o
, int oo
) :
129 LogEvent(EVENT_SLAVEUPDATE
),
133 op(o
), origop(oo
) { }
135 void print(ostream
& out
) const override
{
138 out
<< " " << (int)op
;
139 if (origop
== LINK
) out
<< " link";
140 if (origop
== RENAME
) out
<< " rename";
142 out
<< " for mds." << master
;
146 EMetaBlob
*get_metablob() override
{ return &commit
; }
148 void encode(bufferlist
& bl
, uint64_t features
) const override
;
149 void decode(bufferlist::const_iterator
& bl
) override
;
150 void dump(Formatter
*f
) const override
;
151 static void generate_test_instances(list
<ESlaveUpdate
*>& ls
);
153 void replay(MDSRank
*mds
) override
;
155 WRITE_CLASS_ENCODER_FEATURES(ESlaveUpdate
)