// for tracing. It overrides methods we are interested in tracing and extends
// FSSequentialFileWrapper, which forwards all methods that are not explicitly
// overridden.
-class FSSequentialFileTracingWrapper : public FSSequentialFileWrapper {
+class FSSequentialFileTracingWrapper : public FSSequentialFileOwnerWrapper {
public:
- FSSequentialFileTracingWrapper(FSSequentialFile* t,
+ FSSequentialFileTracingWrapper(std::unique_ptr<FSSequentialFile>&& t,
std::shared_ptr<IOTracer> io_tracer,
const std::string& file_name)
- : FSSequentialFileWrapper(t),
+ : FSSequentialFileOwnerWrapper(std::move(t)),
io_tracer_(io_tracer),
clock_(SystemClock::Default().get()),
file_name_(file_name) {}
FSSequentialFilePtr(std::unique_ptr<FSSequentialFile>&& fs,
const std::shared_ptr<IOTracer>& io_tracer,
const std::string& file_name)
- : fs_(std::move(fs)),
- io_tracer_(io_tracer),
- fs_tracer_(fs_.get(), io_tracer_,
+ : io_tracer_(io_tracer),
+ fs_tracer_(std::move(fs), io_tracer_,
file_name.substr(file_name.find_last_of("/\\") +
1) /* pass file name */) {}
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
return const_cast<FSSequentialFileTracingWrapper*>(&fs_tracer_);
} else {
- return fs_.get();
+ return fs_tracer_.target();
}
}
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
return const_cast<FSSequentialFileTracingWrapper*>(&fs_tracer_);
} else {
- return fs_.get();
+ return fs_tracer_.target();
}
}
private:
- std::unique_ptr<FSSequentialFile> fs_;
std::shared_ptr<IOTracer> io_tracer_;
FSSequentialFileTracingWrapper fs_tracer_;
};
// binary format for tracing. It overrides methods we are interested in tracing
// and extends FSRandomAccessFileWrapper, which forwards all methods that are
// not explicitly overridden.
-class FSRandomAccessFileTracingWrapper : public FSRandomAccessFileWrapper {
+class FSRandomAccessFileTracingWrapper : public FSRandomAccessFileOwnerWrapper {
public:
- FSRandomAccessFileTracingWrapper(FSRandomAccessFile* t,
+ FSRandomAccessFileTracingWrapper(std::unique_ptr<FSRandomAccessFile>&& t,
std::shared_ptr<IOTracer> io_tracer,
const std::string& file_name)
- : FSRandomAccessFileWrapper(t),
+ : FSRandomAccessFileOwnerWrapper(std::move(t)),
io_tracer_(io_tracer),
clock_(SystemClock::Default().get()),
file_name_(file_name) {}
FSRandomAccessFilePtr(std::unique_ptr<FSRandomAccessFile>&& fs,
const std::shared_ptr<IOTracer>& io_tracer,
const std::string& file_name)
- : fs_(std::move(fs)),
- io_tracer_(io_tracer),
- fs_tracer_(fs_.get(), io_tracer_,
+ : io_tracer_(io_tracer),
+ fs_tracer_(std::move(fs), io_tracer_,
file_name.substr(file_name.find_last_of("/\\") +
1) /* pass file name */) {}
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
return const_cast<FSRandomAccessFileTracingWrapper*>(&fs_tracer_);
} else {
- return fs_.get();
+ return fs_tracer_.target();
}
}
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
return const_cast<FSRandomAccessFileTracingWrapper*>(&fs_tracer_);
} else {
- return fs_.get();
+ return fs_tracer_.target();
}
}
private:
- std::unique_ptr<FSRandomAccessFile> fs_;
std::shared_ptr<IOTracer> io_tracer_;
FSRandomAccessFileTracingWrapper fs_tracer_;
};
// for tracing. It overrides methods we are interested in tracing and extends
// FSWritableFileWrapper, which forwards all methods that are not explicitly
// overridden.
-class FSWritableFileTracingWrapper : public FSWritableFileWrapper {
+class FSWritableFileTracingWrapper : public FSWritableFileOwnerWrapper {
public:
- FSWritableFileTracingWrapper(FSWritableFile* t,
+ FSWritableFileTracingWrapper(std::unique_ptr<FSWritableFile>&& t,
std::shared_ptr<IOTracer> io_tracer,
const std::string& file_name)
- : FSWritableFileWrapper(t),
+ : FSWritableFileOwnerWrapper(std::move(t)),
io_tracer_(io_tracer),
clock_(SystemClock::Default().get()),
file_name_(file_name) {}
FSWritableFilePtr(std::unique_ptr<FSWritableFile>&& fs,
const std::shared_ptr<IOTracer>& io_tracer,
const std::string& file_name)
- : fs_(std::move(fs)), io_tracer_(io_tracer) {
+ : io_tracer_(io_tracer) {
fs_tracer_.reset(new FSWritableFileTracingWrapper(
- fs_.get(), io_tracer_,
+ std::move(fs), io_tracer_,
file_name.substr(file_name.find_last_of("/\\") +
1) /* pass file name */));
}
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
return fs_tracer_.get();
} else {
- return fs_.get();
+ return fs_tracer_->target();
}
}
FSWritableFile* get() const {
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
return fs_tracer_.get();
+ } else if (fs_tracer_) {
+ return fs_tracer_->target();
} else {
- return fs_.get();
+ return nullptr;
}
}
void reset() {
- fs_.reset();
fs_tracer_.reset();
io_tracer_ = nullptr;
}
private:
- std::unique_ptr<FSWritableFile> fs_;
std::shared_ptr<IOTracer> io_tracer_;
std::unique_ptr<FSWritableFileTracingWrapper> fs_tracer_;
};
// for tracing. It overrides methods we are interested in tracing and extends
// FSRandomRWFileWrapper, which forwards all methods that are not explicitly
// overridden.
-class FSRandomRWFileTracingWrapper : public FSRandomRWFileWrapper {
+class FSRandomRWFileTracingWrapper : public FSRandomRWFileOwnerWrapper {
public:
- FSRandomRWFileTracingWrapper(FSRandomRWFile* t,
+ FSRandomRWFileTracingWrapper(std::unique_ptr<FSRandomRWFile>&& t,
std::shared_ptr<IOTracer> io_tracer,
const std::string& file_name)
- : FSRandomRWFileWrapper(t),
+ : FSRandomRWFileOwnerWrapper(std::move(t)),
io_tracer_(io_tracer),
clock_(SystemClock::Default().get()),
file_name_(file_name) {}
FSRandomRWFilePtr(std::unique_ptr<FSRandomRWFile>&& fs,
std::shared_ptr<IOTracer> io_tracer,
const std::string& file_name)
- : fs_(std::move(fs)),
- io_tracer_(io_tracer),
- fs_tracer_(fs_.get(), io_tracer_,
+ : io_tracer_(io_tracer),
+ fs_tracer_(std::move(fs), io_tracer_,
file_name.substr(file_name.find_last_of("/\\") +
1) /* pass file name */) {}
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
return const_cast<FSRandomRWFileTracingWrapper*>(&fs_tracer_);
} else {
- return fs_.get();
+ return fs_tracer_.target();
}
}
if (io_tracer_ && io_tracer_->is_tracing_enabled()) {
return const_cast<FSRandomRWFileTracingWrapper*>(&fs_tracer_);
} else {
- return fs_.get();
+ return fs_tracer_.target();
}
}
private:
- std::unique_ptr<FSRandomRWFile> fs_;
std::shared_ptr<IOTracer> io_tracer_;
FSRandomRWFileTracingWrapper fs_tracer_;
};
class FSSequentialFileWrapper : public FSSequentialFile {
public:
+ // Creates a FileWrapper around the input File object and without
+ // taking ownership of the object
explicit FSSequentialFileWrapper(FSSequentialFile* t) : target_(t) {}
FSSequentialFile* target() const { return target_; }
FSSequentialFile* target_;
};
+class FSSequentialFileOwnerWrapper : public FSSequentialFileWrapper {
+ public:
+ // Creates a FileWrapper around the input File object and takes
+ // ownership of the object
+ explicit FSSequentialFileOwnerWrapper(std::unique_ptr<FSSequentialFile>&& t)
+ : FSSequentialFileWrapper(t.get()), guard_(std::move(t)) {}
+
+ private:
+ std::unique_ptr<FSSequentialFile> guard_;
+};
+
class FSRandomAccessFileWrapper : public FSRandomAccessFile {
public:
+ // Creates a FileWrapper around the input File object and without
+ // taking ownership of the object
explicit FSRandomAccessFileWrapper(FSRandomAccessFile* t) : target_(t) {}
FSRandomAccessFile* target() const { return target_; }
}
private:
+ std::unique_ptr<FSRandomAccessFile> guard_;
FSRandomAccessFile* target_;
};
+class FSRandomAccessFileOwnerWrapper : public FSRandomAccessFileWrapper {
+ public:
+ // Creates a FileWrapper around the input File object and takes
+ // ownership of the object
+ explicit FSRandomAccessFileOwnerWrapper(
+ std::unique_ptr<FSRandomAccessFile>&& t)
+ : FSRandomAccessFileWrapper(t.get()), guard_(std::move(t)) {}
+
+ private:
+ std::unique_ptr<FSRandomAccessFile> guard_;
+};
+
class FSWritableFileWrapper : public FSWritableFile {
public:
+ // Creates a FileWrapper around the input File object and without
+ // taking ownership of the object
explicit FSWritableFileWrapper(FSWritableFile* t) : target_(t) {}
FSWritableFile* target() const { return target_; }
FSWritableFile* target_;
};
+class FSWritableFileOwnerWrapper : public FSWritableFileWrapper {
+ public:
+ // Creates a FileWrapper around the input File object and takes
+ // ownership of the object
+ explicit FSWritableFileOwnerWrapper(std::unique_ptr<FSWritableFile>&& t)
+ : FSWritableFileWrapper(t.get()), guard_(std::move(t)) {}
+
+ private:
+ std::unique_ptr<FSWritableFile> guard_;
+};
+
class FSRandomRWFileWrapper : public FSRandomRWFile {
public:
+ // Creates a FileWrapper around the input File object and without
+ // taking ownership of the object
explicit FSRandomRWFileWrapper(FSRandomRWFile* t) : target_(t) {}
FSRandomRWFile* target() const { return target_; }
FSRandomRWFile* target_;
};
+class FSRandomRWFileOwnerWrapper : public FSRandomRWFileWrapper {
+ public:
+ // Creates a FileWrapper around the input File object and takes
+ // ownership of the object
+ explicit FSRandomRWFileOwnerWrapper(std::unique_ptr<FSRandomRWFile>&& t)
+ : FSRandomRWFileWrapper(t.get()), guard_(std::move(t)) {}
+
+ private:
+ std::unique_ptr<FSRandomRWFile> guard_;
+};
+
class FSDirectoryWrapper : public FSDirectory {
public:
+ // Creates a FileWrapper around the input File object and takes
+ // ownership of the object
+ explicit FSDirectoryWrapper(std::unique_ptr<FSDirectory>&& t)
+ : guard_(std::move(t)) {
+ target_ = guard_.get();
+ }
+
+ // Creates a FileWrapper around the input File object and without
+ // taking ownership of the object
explicit FSDirectoryWrapper(FSDirectory* t) : target_(t) {}
IOStatus Fsync(const IOOptions& options, IODebugContext* dbg) override {
}
private:
+ std::unique_ptr<FSDirectory> guard_;
FSDirectory* target_;
};