Skip to content

Commit

Permalink
HDDS-3244. Improve write efficiency by opening RocksDB only once (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
runzhiwang authored Apr 9, 2020
1 parent e2ebbf8 commit b50e932
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
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();

// 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

0 comments on commit b50e932

Please sign in to comment.