Skip to content

Commit

Permalink
HaloDB.size method
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Khodakivskiy committed Dec 2, 2019
1 parent b1f21d1 commit 0329bbb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/oath/halodb/HaloDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public byte[] get(byte[] key) throws HaloDBException {
}
}

public int size(byte[] key) {
return dbInternal.size(key);
}

public boolean put(byte[] key, byte[] value) throws HaloDBException {
try {
return dbInternal.put(key, value);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/oath/halodb/HaloDBInternal.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,15 @@ long size() {
return inMemoryIndex.size();
}

int size(byte[] key) {
InMemoryIndexMetaData metaData = inMemoryIndex.get(key);
if (metaData == null) {
return -1;
}

return metaData.getValueSize();
}

void setIOErrorFlag() throws IOException {
DBMetaData metaData = new DBMetaData(dbDirectory);
metaData.loadFromFileIfExists();
Expand Down

0 comments on commit 0329bbb

Please sign in to comment.