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 "../LogEvent.h"
19 #include "EMetaBlob.h"
22 * rollback records, for remote/slave updates, which may need to be manually
23 * rolled back during journal replay. (or while active if master fails, but in
24 * that case these records aren't needed.)
26 struct link_rollback {
31 utime_t old_dir_mtime;
32 utime_t old_dir_rctime;
34 link_rollback() : ino(0), was_inc(false) {}
36 void encode(bufferlist& bl) const;
37 void decode(bufferlist::iterator& bl);
38 void dump(Formatter *f) const;
39 static void generate_test_instances(list<link_rollback*>& ls);
41 WRITE_CLASS_ENCODER(link_rollback)
44 * this is only used on an empty dir with a dirfrag on a remote node.
45 * we are auth for nothing. all we need to do is relink the directory
46 * in the hierarchy properly during replay to avoid breaking the
49 struct rmdir_rollback {
56 void encode(bufferlist& bl) const;
57 void decode(bufferlist::iterator& bl);
58 void dump(Formatter *f) const;
59 static void generate_test_instances(list<rmdir_rollback*>& ls);
61 WRITE_CLASS_ENCODER(rmdir_rollback)
63 struct rename_rollback {
66 utime_t dirfrag_old_mtime;
67 utime_t dirfrag_old_rctime;
68 inodeno_t ino, remote_ino;
73 drec() : remote_d_type((char)S_IFREG) {}
75 void encode(bufferlist& bl) const;
76 void decode(bufferlist::iterator& bl);
77 void dump(Formatter *f) const;
78 static void generate_test_instances(list<drec*>& ls);
80 WRITE_CLASS_MEMBER_ENCODER(drec)
83 drec orig_src, orig_dest;
84 drec stray; // we know this is null, but we want dname, old mtime/rctime
87 void encode(bufferlist& bl) const;
88 void decode(bufferlist::iterator& bl);
89 void dump(Formatter *f) const;
90 static void generate_test_instances(list<rename_rollback*>& ls);
92 WRITE_CLASS_ENCODER(rename_rollback::drec)
93 WRITE_CLASS_ENCODER(rename_rollback)
96 class ESlaveUpdate : public LogEvent {
98 const static int OP_PREPARE = 1;
99 const static int OP_COMMIT = 2;
100 const static int OP_ROLLBACK = 3;
102 const static int LINK = 1;
103 const static int RENAME = 2;
104 const static int RMDIR = 3;
107 * we journal a rollback metablob that contains the unmodified metadata
108 * too, because we may be updating previously dirty metadata, which
109 * will allow old log segments to be trimmed. if we end of rolling back,
110 * those updates could be lost.. so we re-journal the unmodified metadata,
111 * and replay will apply _either_ commit or rollback.
118 __u8 op; // prepare, commit, abort
119 __u8 origop; // link | rename
121 ESlaveUpdate() : LogEvent(EVENT_SLAVEUPDATE), master(0), op(0), origop(0) { }
122 ESlaveUpdate(MDLog *mdlog, const char *s, metareqid_t ri, int mastermds, int o, int oo) :
123 LogEvent(EVENT_SLAVEUPDATE), commit(mdlog),
127 op(o), origop(oo) { }
129 void print(ostream& out) const override {
132 out << " " << (int)op;
133 if (origop == LINK) out << " link";
134 if (origop == RENAME) out << " rename";
136 out << " for mds." << master;
140 EMetaBlob *get_metablob() override { return &commit; }
142 void encode(bufferlist& bl, uint64_t features) const override;
143 void decode(bufferlist::iterator& bl) override;
144 void dump(Formatter *f) const override;
145 static void generate_test_instances(list<ESlaveUpdate*>& ls);
147 void replay(MDSRank *mds) override;
149 WRITE_CLASS_ENCODER_FEATURES(ESlaveUpdate)