Skip to content

Commit

Permalink
Move WBWIIterator out of public include
Browse files Browse the repository at this point in the history
for enhancement #51
  • Loading branch information
rockeet committed Aug 16, 2023
1 parent f51b2f3 commit c757999
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 50 deletions.
53 changes: 3 additions & 50 deletions include/rocksdb/utilities/write_batch_with_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,62 +52,15 @@ struct WriteEntry {
};

// Iterator of one column family out of a WriteBatchWithIndex.
class WBWIIterator {
public:
virtual ~WBWIIterator() {}

virtual bool Valid() const = 0;

virtual void SeekToFirst() = 0;

virtual void SeekToLast() = 0;

virtual void Seek(const Slice& key) = 0;

virtual void SeekForPrev(const Slice& key) = 0;

virtual void Next() = 0;

virtual void Prev() = 0;

// the return WriteEntry is only valid until the next mutation of
// WriteBatchWithIndex
virtual WriteEntry Entry() const = 0;

virtual Slice user_key() const = 0;

virtual Status status() const = 0;

//-------------------------------------------------------------------------
// topling specific: copy from WBWIIteratorImpl as pure virtual,
// to reuse BaseDeltaIterator.
// just for reuse, many class is not required to be visiable by external code!
class WBWIIterator; // forward declaration
struct WBWIIterEnum {
enum Result : uint8_t {
kFound,
kDeleted,
kNotFound,
kMergeInProgress,
kError
};

// Moves the iterator to first entry of the previous key.
virtual bool PrevKey() = 0; // returns same as following Valid()
// Moves the iterator to first entry of the next key.
virtual bool NextKey() = 0; // returns same as following Valid()

virtual bool EqualsKey(const Slice& key) const = 0;

// Moves the iterator to the Update (Put or Delete) for the current key
// If there are no Put/Delete, the Iterator will point to the first entry for
// this key
// @return kFound if a Put was found for the key
// @return kDeleted if a delete was found for the key
// @return kMergeInProgress if only merges were fouund for the key
// @return kError if an unsupported operation was found for the key
// @return kNotFound if no operations were found for this key
//
virtual Result FindLatestUpdate(const Slice& key, MergeContext*);
virtual Result FindLatestUpdate(MergeContext*);
};

// A WriteBatchWithIndex with a binary searchable index built for all the keys
Expand Down Expand Up @@ -261,7 +214,7 @@ class WriteBatchWithIndex : public WriteBatchBase {
return GetFromBatch(nullptr, options, key, value);
}

virtual WBWIIterator::Result
virtual WBWIIterEnum::Result
GetFromBatchRaw(DB*, ColumnFamilyHandle*, const Slice& key,
MergeContext*, std::string* value, Status*);

Expand Down
1 change: 1 addition & 0 deletions java/rocksjni/write_batch_with_index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// calling c++ ROCKSDB_NAMESPACE::WriteBatchWithIndex methods from Java side.

#include "rocksdb/utilities/write_batch_with_index.h"
#include "utilities/write_batch_with_index/write_batch_with_index_internal.h"

#include "include/org_rocksdb_WBWIRocksIterator.h"
#include "include/org_rocksdb_WriteBatchWithIndex.h"
Expand Down
55 changes: 55 additions & 0 deletions utilities/write_batch_with_index/write_batch_with_index_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,61 @@ class WBWIIteratorImpl;
class WriteBatchWithIndexInternal;
struct Options;

// We move WBWIIterator out of public include, but old WBWIIterator::Result was
// used by WriteBatchWithIndex::GetFromBatchRaw(), so WBWIIterator::Result is
// moved from here to write_batch_with_index.h and named as WBWIIterEnum::Result,
// derive from WBWIIterEnum is to avoid change old code
class WBWIIterator : public WBWIIterEnum {
public:
virtual ~WBWIIterator() {}

virtual bool Valid() const = 0;

virtual void SeekToFirst() = 0;

virtual void SeekToLast() = 0;

virtual void Seek(const Slice& key) = 0;

virtual void SeekForPrev(const Slice& key) = 0;

virtual void Next() = 0;

virtual void Prev() = 0;

// the return WriteEntry is only valid until the next mutation of
// WriteBatchWithIndex
virtual WriteEntry Entry() const = 0;

virtual Slice user_key() const = 0;

virtual Status status() const = 0;

//-------------------------------------------------------------------------
// topling specific: copy from WBWIIteratorImpl as pure virtual,
// to reuse BaseDeltaIterator.
// just for reuse, many class is not required to be visiable by external code!

// Moves the iterator to first entry of the previous key.
virtual bool PrevKey() = 0; // returns same as following Valid()
// Moves the iterator to first entry of the next key.
virtual bool NextKey() = 0; // returns same as following Valid()

virtual bool EqualsKey(const Slice& key) const = 0;

// Moves the iterator to the Update (Put or Delete) for the current key
// If there are no Put/Delete, the Iterator will point to the first entry for
// this key
// @return kFound if a Put was found for the key
// @return kDeleted if a delete was found for the key
// @return kMergeInProgress if only merges were fouund for the key
// @return kError if an unsupported operation was found for the key
// @return kNotFound if no operations were found for this key
//
virtual Result FindLatestUpdate(const Slice& key, MergeContext*);
virtual Result FindLatestUpdate(MergeContext*);
};

// when direction == forward
// * current_at_base_ <=> base_iterator > delta_iterator
// when direction == backwards
Expand Down

0 comments on commit c757999

Please sign in to comment.