Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-3244. Improve write efficiency by opening RocksDB only once #709

Merged
merged 4 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,19 @@ public void removeDB(String containerDBPath) {
lock.unlock();
}
}

/**
* Add a DB handler into cache.
*
* @param containerDBPath - DB path of the container.
* @param db - DB handler
*/
public void addDB(String containerDBPath, ReferenceCountedDB db) {
lock.lock();
try {
this.putIfAbsent(containerDBPath, db);
} finally {
lock.unlock();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ public static void shutdownCache(ContainerCache cache) {
cache.shutdownCache();
}

/**
* Add a DB handler into cache.
*
* @param db - DB handler.
* @param containerDBPath - DB path of the container.
* @param conf configuration.
*/
public static void addDB(ReferenceCountedDB db, String containerDBPath,
Configuration conf) {
ContainerCache cache = ContainerCache.getInstance(conf);
Preconditions.checkNotNull(cache);
cache.addDB(containerDBPath, db);
}

/**
* Parses the {@link BlockData} from a bytes array.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ public static void createContainerMetaData(File containerMetaDataPath, File
throw new IOException("Unable to create directory for metadata storage." +
" Path: " + containerMetaDataPath);
}
MetadataStore store = MetadataStoreBuilder.newBuilder().setConf(conf)
.setCreateIfMissing(true).setDbFile(dbFile).build();
runzhiwang marked this conversation as resolved.
Show resolved Hide resolved

// we close since the SCM pre-creates containers.
// we will open and put Db handle into a cache when keys are being created
// in a container.

store.close();

if (!chunksPath.mkdirs()) {
LOG.error("Unable to create chunks directory Container {}",
Expand All @@ -91,6 +83,13 @@ public static void createContainerMetaData(File containerMetaDataPath, File
throw new IOException("Unable to create directory for data storage." +
" Path: " + chunksPath);
}

MetadataStore store = MetadataStoreBuilder.newBuilder().setConf(conf)
.setCreateIfMissing(true).setDbFile(dbFile).build();
ReferenceCountedDB db =
new ReferenceCountedDB(store, dbFile.getAbsolutePath());
//add db handler into cache
BlockUtils.addDB(db, dbFile.getAbsolutePath(), conf);
}

/**
Expand Down