Skip to content

Commit

Permalink
Some updates for SpatialDB
Browse files Browse the repository at this point in the history
Summary:
1. add db statistics
2. write out batch every millionth write

Test Plan: unit tests

Reviewers: ljin, sdong, yinwang

Reviewed By: yinwang

Differential Revision: https://reviews.facebook.net/D22755
  • Loading branch information
igorcanadi committed Sep 9, 2014
1 parent 171d4ff commit 55114e7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions utilities/spatialdb/spatial_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "rocksdb/options.h"
#include "rocksdb/memtablerep.h"
#include "rocksdb/slice_transform.h"
#include "rocksdb/statistics.h"
#include "rocksdb/table.h"
#include "rocksdb/db.h"
#include "rocksdb/utilities/stackable_db.h"
Expand Down Expand Up @@ -516,6 +517,7 @@ class SpatialDBImpl : public SpatialDB {
return Status::InvalidArgument("Spatial indexes can't be empty");
}

const int kWriteOutEveryBytes = 1024 * 1024; // 1MB
uint64_t id = next_id_.fetch_add(1);

for (const auto& si : spatial_indexes) {
Expand All @@ -537,6 +539,13 @@ class SpatialDBImpl : public SpatialDB {
&key, GetQuadKeyFromTile(x, y, spatial_index.tile_bits));
PutFixed64BigEndian(&key, id);
batch.Put(itr->second.column_family, key, Slice());
if (batch.GetDataSize() >= kWriteOutEveryBytes) {
Status s = Write(write_options, &batch);
batch.Clear();
if (!s.ok()) {
return s;
}
}
}
}
}
Expand All @@ -553,6 +562,7 @@ class SpatialDBImpl : public SpatialDB {
}

virtual Status Compact() override {
// TODO(icanadi) maybe do this in parallel?
Status s, t;
for (auto& iter : name_to_index_) {
t = Flush(FlushOptions(), iter.second.column_family);
Expand Down Expand Up @@ -625,15 +635,20 @@ class SpatialDBImpl : public SpatialDB {
namespace {
DBOptions GetDBOptions(const SpatialDBOptions& options) {
DBOptions db_options;
db_options.max_open_files = 50000;
db_options.max_background_compactions = 3 * options.num_threads / 4;
db_options.max_background_flushes =
options.num_threads - db_options.max_background_compactions;
db_options.env->SetBackgroundThreads(db_options.max_background_compactions,
Env::LOW);
db_options.env->SetBackgroundThreads(db_options.max_background_flushes,
Env::HIGH);
db_options.statistics = CreateDBStatistics();
if (options.bulk_load) {
db_options.stats_dump_period_sec = 600;
db_options.disableDataSync = true;
} else {
db_options.stats_dump_period_sec = 1800; // 30min
}
return db_options;
}
Expand All @@ -643,6 +658,8 @@ ColumnFamilyOptions GetColumnFamilyOptions(const SpatialDBOptions& options,
ColumnFamilyOptions column_family_options;
column_family_options.write_buffer_size = 128 * 1024 * 1024; // 128MB
column_family_options.max_write_buffer_number = 4;
column_family_options.max_bytes_for_level_base = 256 * 1024 * 1024; // 256MB
column_family_options.target_file_size_base = 64 * 1024 * 1024; // 64MB
column_family_options.level0_file_num_compaction_trigger = 2;
column_family_options.level0_slowdown_writes_trigger = 16;
column_family_options.level0_slowdown_writes_trigger = 32;
Expand Down

0 comments on commit 55114e7

Please sign in to comment.