Package org.apache.bookkeeper.metastore
Class InMemoryMetastoreTable
- java.lang.Object
-
- org.apache.bookkeeper.metastore.InMemoryMetastoreTable
-
- All Implemented Interfaces:
MetastoreScannableTable
,MetastoreTable
public class InMemoryMetastoreTable extends java.lang.Object implements MetastoreScannableTable
An in-memory implementation of a Metastore table.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
InMemoryMetastoreTable.MetadataVersion
An implementation of the Version interface for metadata.(package private) static class
InMemoryMetastoreTable.Result<T>
-
Nested classes/interfaces inherited from interface org.apache.bookkeeper.metastore.MetastoreScannableTable
MetastoreScannableTable.Order
-
-
Field Summary
-
Fields inherited from interface org.apache.bookkeeper.metastore.MetastoreScannableTable
EMPTY_END_KEY, EMPTY_START_KEY
-
Fields inherited from interface org.apache.bookkeeper.metastore.MetastoreTable
ALL_FIELDS, NON_FIELDS
-
-
Constructor Summary
Constructors Constructor Description InMemoryMetastoreTable(InMemoryMetaStore metastore, java.lang.String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static Versioned<Value>
cloneValue(Value value, Version version, java.util.Set<java.lang.String> fields)
void
close()
Close the table.void
get(java.lang.String key, java.util.Set<java.lang.String> fields, MetastoreCallback<Versioned<Value>> cb, java.lang.Object ctx)
Get specified fields of a key.void
get(java.lang.String key, MetastoreCallback<Versioned<Value>> cb, java.lang.Object ctx)
Get all fields of a key.void
get(java.lang.String key, MetastoreWatcher watcher, MetastoreCallback<Versioned<Value>> cb, java.lang.Object ctx)
Get all fields of a key.java.lang.String
getName()
Get table name.void
openCursor(java.lang.String firstKey, boolean firstInclusive, java.lang.String lastKey, boolean lastInclusive, MetastoreScannableTable.Order order, java.util.Set<java.lang.String> fields, MetastoreCallback<MetastoreCursor> cb, java.lang.Object ctx)
Open a cursor to loop over the entries belonging to a key range, which returns the specifiedfields
for each entry.void
openCursor(java.lang.String firstKey, boolean firstInclusive, java.lang.String lastKey, boolean lastInclusive, MetastoreScannableTable.Order order, MetastoreCallback<MetastoreCursor> cb, java.lang.Object ctx)
Open a cursor to loop over the entries belonging to a key range, which returns all fields for each entry.void
openCursor(java.util.Set<java.lang.String> fields, MetastoreCallback<MetastoreCursor> cb, java.lang.Object ctx)
Open a cursor to loop over all the entries of the table, which returns the specifiedfields
for each entry.void
openCursor(MetastoreCallback<MetastoreCursor> cb, java.lang.Object ctx)
Open a cursor to loop over all the entries of the table, which returns all fields for each entry.void
put(java.lang.String key, Value value, Version version, MetastoreCallback<Version> cb, java.lang.Object ctx)
Update a key according to its version.void
remove(java.lang.String key, Version version, MetastoreCallback<java.lang.Void> cb, java.lang.Object ctx)
Remove a key by its version.void
scheduleGet(java.lang.String key, java.util.Set<java.lang.String> fields, MetastoreCallback<Versioned<Value>> cb, java.lang.Object ctx)
-
-
-
Constructor Detail
-
InMemoryMetastoreTable
public InMemoryMetastoreTable(InMemoryMetaStore metastore, java.lang.String name)
-
-
Method Detail
-
getName
public java.lang.String getName()
Description copied from interface:MetastoreTable
Get table name.- Specified by:
getName
in interfaceMetastoreTable
- Returns:
- table name
-
cloneValue
static Versioned<Value> cloneValue(Value value, Version version, java.util.Set<java.lang.String> fields)
-
get
public void get(java.lang.String key, MetastoreCallback<Versioned<Value>> cb, java.lang.Object ctx)
Description copied from interface:MetastoreTable
Get all fields of a key.Return Code:
MSException.Code.OK
: success returning the keyMSException.Code.NoKey
: no key foundMSException.Code.IllegalOp
/MSException.Code.ServiceDown
: other issues
- Specified by:
get
in interfaceMetastoreTable
- Parameters:
key
- Key Namecb
- Callback to return all fields of the keyctx
- Callback context
-
get
public void get(java.lang.String key, MetastoreWatcher watcher, MetastoreCallback<Versioned<Value>> cb, java.lang.Object ctx)
Description copied from interface:MetastoreTable
Get all fields of a key.Return Code:
MSException.Code.OK
: success returning the keyMSException.Code.NoKey
: no key foundMSException.Code.IllegalOp
/MSException.Code.ServiceDown
: other issues
- Specified by:
get
in interfaceMetastoreTable
- Parameters:
key
- Key Namewatcher
- Watcher object to receive notificationscb
- Callback to return all fields of the keyctx
- Callback context
-
get
public void get(java.lang.String key, java.util.Set<java.lang.String> fields, MetastoreCallback<Versioned<Value>> cb, java.lang.Object ctx)
Description copied from interface:MetastoreTable
Get specified fields of a key.Return Code:
MSException.Code.OK
: success returning the keyMSException.Code.NoKey
: no key foundMSException.Code.IllegalOp
/MSException.Code.ServiceDown
: other issues
- Specified by:
get
in interfaceMetastoreTable
- Parameters:
key
- Key Namefields
- Fields to returncb
- Callback to return specified fields of the keyctx
- Callback context
-
scheduleGet
public void scheduleGet(java.lang.String key, java.util.Set<java.lang.String> fields, MetastoreCallback<Versioned<Value>> cb, java.lang.Object ctx)
-
put
public void put(java.lang.String key, Value value, Version version, MetastoreCallback<Version> cb, java.lang.Object ctx)
Description copied from interface:MetastoreTable
Update a key according to its version.Return Code:
MSException.Code.OK
: success updating the keyMSException.Code.BadVersion
: failed to update the key due to bad versionMSException.Code.NoKey
: no key found to update data, if not providedVersion.NEW
MSException.Code.KeyExists
: entry exists providingVersion.NEW
MSException.Code.IllegalOp
/MSException.Code.ServiceDown
: other issues
The key is updated only when the version matches its current version. In particular, if the provided version is:
Version.ANY
: update the data without comparing its version. Note this usage is not encouraged since it may mess up data consistency.Version.NEW
: create the entry if it doesn't exist before; Otherwise returnMSException.Code.KeyExists
.
- Specified by:
put
in interfaceMetastoreTable
- Parameters:
key
- Key Namevalue
- Value to update.version
- Version specified to update.cb
- Callback to return new version after updated.ctx
- Callback context
-
remove
public void remove(java.lang.String key, Version version, MetastoreCallback<java.lang.Void> cb, java.lang.Object ctx)
Description copied from interface:MetastoreTable
Remove a key by its version.The key is removed only when the version matches its current version. If
version
isVersion.ANY
, the key would be removed directly.Return Code:
MSException.Code.OK
: success updating the keyMSException.Code.NoKey
: if the key doesn't exist.MSException.Code.BadVersion
: failed to delete the key due to bad versionMSException.Code.IllegalOp
/MSException.Code.ServiceDown
: other issues
- Specified by:
remove
in interfaceMetastoreTable
- Parameters:
key
- Key Name.version
- Version specified to remove.cb
- Callback to return all fields of the keyctx
- Callback context
-
openCursor
public void openCursor(MetastoreCallback<MetastoreCursor> cb, java.lang.Object ctx)
Description copied from interface:MetastoreTable
Open a cursor to loop over all the entries of the table, which returns all fields for each entry. The returned cursor doesn't need to guarantee any order, since the underlying might be a hash table or an order table.- Specified by:
openCursor
in interfaceMetastoreTable
- Parameters:
cb
- Callback to return an opened cursorctx
- Callback context
-
openCursor
public void openCursor(java.util.Set<java.lang.String> fields, MetastoreCallback<MetastoreCursor> cb, java.lang.Object ctx)
Description copied from interface:MetastoreTable
Open a cursor to loop over all the entries of the table, which returns the specifiedfields
for each entry. The returned cursor doesn't need to guarantee any order, since the underlying might be a hash table or an order table.- Specified by:
openCursor
in interfaceMetastoreTable
- Parameters:
fields
- Fields to selectcb
- Callback to return an opened cursorctx
- Callback context
-
openCursor
public void openCursor(java.lang.String firstKey, boolean firstInclusive, java.lang.String lastKey, boolean lastInclusive, MetastoreScannableTable.Order order, MetastoreCallback<MetastoreCursor> cb, java.lang.Object ctx)
Description copied from interface:MetastoreScannableTable
Open a cursor to loop over the entries belonging to a key range, which returns all fields for each entry.Return Code:
MSException.Code.OK
: an opened cursor
MSException.Code.IllegalOp
/MSException.Code.ServiceDown
: other issues- Specified by:
openCursor
in interfaceMetastoreScannableTable
- Parameters:
firstKey
- Key to start scanning. If it isMetastoreScannableTable.EMPTY_START_KEY
, it starts from first key (inclusive).firstInclusive
- true if firstKey is to be included in the returned view.lastKey
- Key to stop scanning. If it isMetastoreScannableTable.EMPTY_END_KEY
, scan ends at the lastKey of the table (inclusive).lastInclusive
- true if lastKey is to be included in the returned view.order
- the order to loop over the entriescb
- Callback to return an opened cursor.ctx
- Callback context
-
openCursor
public void openCursor(java.lang.String firstKey, boolean firstInclusive, java.lang.String lastKey, boolean lastInclusive, MetastoreScannableTable.Order order, java.util.Set<java.lang.String> fields, MetastoreCallback<MetastoreCursor> cb, java.lang.Object ctx)
Description copied from interface:MetastoreScannableTable
Open a cursor to loop over the entries belonging to a key range, which returns the specifiedfields
for each entry.Return Code:
MSException.Code.OK
: an opened cursor
MSException.Code.IllegalOp
/MSException.Code.ServiceDown
: other issues- Specified by:
openCursor
in interfaceMetastoreScannableTable
- Parameters:
firstKey
- Key to start scanning. If it isMetastoreScannableTable.EMPTY_START_KEY
, it starts from first key (inclusive).firstInclusive
- true if firstKey is to be included in the returned view.lastKey
- Key to stop scanning. If it isMetastoreScannableTable.EMPTY_END_KEY
, scan ends at the lastKey of the table (inclusive).lastInclusive
- true if lastKey is to be included in the returned view.order
- the order to loop over the entriesfields
- Fields to selectcb
- Callback to return an opened cursor.ctx
- Callback context
-
close
public void close()
Description copied from interface:MetastoreTable
Close the table.- Specified by:
close
in interfaceMetastoreTable
-
-