@@ -50,6 +50,10 @@ struct FilterBuildingContext;
5050// a number of built-in CompressionTypes that ignore any dictionary block in
5151// the file; therefore they cannot accommodate dictionary compression in the
5252// future without a schema change / extension.)
53+ //
54+ // Exceptions MUST NOT propagate out of overridden functions into RocksDB,
55+ // because RocksDB is not exception-safe. This could cause undefined behavior
56+ // including data loss, unreported corruption, deadlocks, and more.
5357class Compressor {
5458 public:
5559 Compressor () = default ;
@@ -134,15 +138,15 @@ class Compressor {
134138 // EXTENSIBLE or reinterpret_cast-able by custom Compressor implementations
135139 struct WorkingArea {};
136140
137- protected:
138141 // To allow for flexible re-use / reclaimation, we have explicit Get and
139142 // Release functions, and usually wrap in a special RAII smart pointer.
140143 // For example, a WorkingArea could be saved/recycled in thread-local or
141144 // core-local storage, or heap managed, etc., though an explicit WorkingArea
142145 // is only advised for repeated compression (by a single thread).
146+ // ReleaseWorkingArea() in not intended to be called directly, but used by
147+ // ManagedWorkingArea.
143148 virtual void ReleaseWorkingArea (WorkingArea*) {}
144149
145- public:
146150 using ManagedWorkingArea =
147151 ManagedPtr<WorkingArea, Compressor, &Compressor::ReleaseWorkingArea>;
148152
@@ -221,6 +225,10 @@ class Compressor {
221225// decompressed into part of a single buffer allocated to hold a block's
222226// uncompressed contents along with an in-memory object representation of the
223227// block (to reduce fragmentation and other overheads of separate objects).
228+ //
229+ // Exceptions MUST NOT propagate out of overridden functions into RocksDB,
230+ // because RocksDB is not exception-safe. This could cause undefined behavior
231+ // including data loss, unreported corruption, deadlocks, and more.
224232class Decompressor {
225233 public:
226234 Decompressor () = default ;
@@ -278,6 +286,9 @@ class Decompressor {
278286 // supported for this kind of Decompressor. Corruption - dictionary is
279287 // malformed (though many implementations will accept any data as a
280288 // dictionary)
289+ //
290+ // RocksDB promises not to call this function with an empty dictionary slice
291+ // (equivalent to no dictionary).
281292 virtual Status MaybeCloneForDict (const Slice& /* serialized_dict*/ ,
282293 std::unique_ptr<Decompressor>* /* out*/ ) {
283294 return Status::NotSupported (
@@ -339,6 +350,10 @@ class Decompressor {
339350// (because that would break backward compatibility, potential quiet
340351// corruption)
341352// TODO: consider adding optional streaming compression support (low priority)
353+ //
354+ // Exceptions MUST NOT propagate out of overridden functions into RocksDB,
355+ // because RocksDB is not exception-safe. This could cause undefined behavior
356+ // including data loss, unreported corruption, deadlocks, and more.
342357class CompressionManager
343358 : public std::enable_shared_from_this<CompressionManager>,
344359 public Customizable {
@@ -466,6 +481,10 @@ class CompressorWrapper : public Compressor {
466481 return wrapped_->ObtainWorkingArea ();
467482 }
468483
484+ // NOTE: Don't need to override ReleaseWorkingArea() here because
485+ // ManagedWorkingArea takes care of calling it on the Compressor that created
486+ // the WorkingArea.
487+
469488 Status CompressBlock (Slice uncompressed_data, std::string* compressed_output,
470489 CompressionType* out_compression_type,
471490 ManagedWorkingArea* working_area) override {
@@ -491,6 +510,10 @@ class DecompressorWrapper : public Decompressor {
491510 wrapped_->ReleaseWorkingArea (wa);
492511 }
493512
513+ // NOTE: Don't need to override ReleaseWorkingArea() here because
514+ // ManagedWorkingArea takes care of calling it on the Decompressor that
515+ // created the WorkingArea.
516+
494517 ManagedWorkingArea ObtainWorkingArea (CompressionType preferred) override {
495518 return wrapped_->ObtainWorkingArea (preferred);
496519 }
0 commit comments