Skip to content
This repository has been archived by the owner on Apr 30, 2019. It is now read-only.

Support DbLedgerStorage in LedgerCmd to get list of logger files for a given ledgerId #6

Merged
merged 4 commits into from
Jun 16, 2017

Conversation

rdhabalia
Copy link

Motivation

In certain conditions client may require to get list of entryLog files that contain given ledgerId for specific auditing or cleanup. Right now, LedgerCmd under BookieShell gives similar information but it doesn't support DbLedgerStorage so, added support for DbLedgerStorage to LedgerCmd.

Modifications

Add DbLedgerStorage support under BookieShell.LedgerCmd.

}
} finally {
ledgersDb.close();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels way too much like you are reaching into the internals of EntryLocationIndex. Even though we do very similar things in other parts of this same file, I really would prefer to at least see the internals of most of this moving to EntryLocationIndex.java, so the code that messes with this DB is all in the same file.

In fact it looks like you could use

https://github.com/yahoo/bookkeeper/blob/yahoo-4.3/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java#L77-L94

for almost all of this, and no need for accessing ArrayUtil

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's correct, I have implemented it earlier because we have to initialize rocksDB in read-only mode and we can do it by passing custom KeyValueStorageFactory so, we can reuse EntryLocationIndex. I have changed it to use EntryLocationIndex for getting ledger location.

LOG.info("Create ledger and add entries to it");
LedgerHandle lh1 = createLedgerWithEntries(bk, 10);

Thread.sleep(1000); // sleep to flush entries to logger file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no other way to force it to sync?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, removed it by decreasing flush time.

@rdhabalia rdhabalia force-pushed the tool_ledger branch 3 times, most recently from 2540c2d to fd0367c Compare May 24, 2017 18:53
long pos = offset & 0xffffffffL;
System.out.println("entry " + curEntry + "\t:\t(log: " + entryLogId + ", pos: " + pos + ")");
} catch (Exception e) {
System.err.println("ERROR: while getting location for entry " + ledgerId + ", " + curEntry + ", "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A single bookie is not required to have all the entries for a particular ledger.

If you have e=3 w=2 a=2 for example, each bookie will be missing 1 entry out of 3, we shouldn't break the loop at that point.

Also, the first entry might be very after 0. Eg: when a bookie crashes (or times out), the client will keep using the same ledger and form a new ensemble by removing the old bookie and picking a new one.
The new bookie will only have entries from that point on.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A single bookie is not required to have all the entries for a particular ledger.

Yes, in that case we should not break and continue. Fixed it,

* @return
* @throws IOException if failed to init KeyValueStorageRocksDB
*/
protected int readLedgerIndexEntriesFromDbLedgerStorage(long ledgerId) throws IOException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing: Since this is specific to DbLedgerStorage, should we have the code in that class too?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually DbLedgerStorage initializes multiple things other than EntryLocationIndex such as
LedgerMetadataIndex, GC, EntryLogger. And also, this cmd requires EntryLocationIndex instance which starts rocksDB in readOnly mode by passing custom KeyValueStorageFactory factory. So, I think it's bettter to keep this code in Cmd rather adding different init method in DbStorage just for EntryLocationIndex . Any thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I was thinking more like a static method in there or to add a class in the ..storage.ldb. package, just to keep all the DbLederStorage specific code contained in one place as much as possible.

@rdhabalia rdhabalia force-pushed the tool_ledger branch 3 times, most recently from e1534a2 to 30da591 Compare May 25, 2017 06:38
Copy link
Collaborator

@revans2 revans2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good to me, but I'll defer to @merlimat who really knows the code a lot better than I do.

Copy link
Collaborator

@merlimat merlimat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@rdhabalia rdhabalia merged commit 384414b into YahooArchive:yahoo-4.3 Jun 16, 2017
revans2 pushed a commit that referenced this pull request Jun 21, 2017
rdhabalia pushed a commit to rdhabalia/bookkeeper that referenced this pull request Sep 25, 2018
* Use statelib to store metadata

* Remove namespace

* Use local state store to store root range
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants