Skip to content

Commit 55114e7

Browse files
committed
Some updates for SpatialDB
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
1 parent 171d4ff commit 55114e7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

utilities/spatialdb/spatial_db.cc

+17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "rocksdb/options.h"
2323
#include "rocksdb/memtablerep.h"
2424
#include "rocksdb/slice_transform.h"
25+
#include "rocksdb/statistics.h"
2526
#include "rocksdb/table.h"
2627
#include "rocksdb/db.h"
2728
#include "rocksdb/utilities/stackable_db.h"
@@ -516,6 +517,7 @@ class SpatialDBImpl : public SpatialDB {
516517
return Status::InvalidArgument("Spatial indexes can't be empty");
517518
}
518519

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

521523
for (const auto& si : spatial_indexes) {
@@ -537,6 +539,13 @@ class SpatialDBImpl : public SpatialDB {
537539
&key, GetQuadKeyFromTile(x, y, spatial_index.tile_bits));
538540
PutFixed64BigEndian(&key, id);
539541
batch.Put(itr->second.column_family, key, Slice());
542+
if (batch.GetDataSize() >= kWriteOutEveryBytes) {
543+
Status s = Write(write_options, &batch);
544+
batch.Clear();
545+
if (!s.ok()) {
546+
return s;
547+
}
548+
}
540549
}
541550
}
542551
}
@@ -553,6 +562,7 @@ class SpatialDBImpl : public SpatialDB {
553562
}
554563

555564
virtual Status Compact() override {
565+
// TODO(icanadi) maybe do this in parallel?
556566
Status s, t;
557567
for (auto& iter : name_to_index_) {
558568
t = Flush(FlushOptions(), iter.second.column_family);
@@ -625,15 +635,20 @@ class SpatialDBImpl : public SpatialDB {
625635
namespace {
626636
DBOptions GetDBOptions(const SpatialDBOptions& options) {
627637
DBOptions db_options;
638+
db_options.max_open_files = 50000;
628639
db_options.max_background_compactions = 3 * options.num_threads / 4;
629640
db_options.max_background_flushes =
630641
options.num_threads - db_options.max_background_compactions;
631642
db_options.env->SetBackgroundThreads(db_options.max_background_compactions,
632643
Env::LOW);
633644
db_options.env->SetBackgroundThreads(db_options.max_background_flushes,
634645
Env::HIGH);
646+
db_options.statistics = CreateDBStatistics();
635647
if (options.bulk_load) {
648+
db_options.stats_dump_period_sec = 600;
636649
db_options.disableDataSync = true;
650+
} else {
651+
db_options.stats_dump_period_sec = 1800; // 30min
637652
}
638653
return db_options;
639654
}
@@ -643,6 +658,8 @@ ColumnFamilyOptions GetColumnFamilyOptions(const SpatialDBOptions& options,
643658
ColumnFamilyOptions column_family_options;
644659
column_family_options.write_buffer_size = 128 * 1024 * 1024; // 128MB
645660
column_family_options.max_write_buffer_number = 4;
661+
column_family_options.max_bytes_for_level_base = 256 * 1024 * 1024; // 256MB
662+
column_family_options.target_file_size_base = 64 * 1024 * 1024; // 64MB
646663
column_family_options.level0_file_num_compaction_trigger = 2;
647664
column_family_options.level0_slowdown_writes_trigger = 16;
648665
column_family_options.level0_slowdown_writes_trigger = 32;

0 commit comments

Comments
 (0)