22
22
#include " rocksdb/options.h"
23
23
#include " rocksdb/memtablerep.h"
24
24
#include " rocksdb/slice_transform.h"
25
+ #include " rocksdb/statistics.h"
25
26
#include " rocksdb/table.h"
26
27
#include " rocksdb/db.h"
27
28
#include " rocksdb/utilities/stackable_db.h"
@@ -516,6 +517,7 @@ class SpatialDBImpl : public SpatialDB {
516
517
return Status::InvalidArgument (" Spatial indexes can't be empty" );
517
518
}
518
519
520
+ const int kWriteOutEveryBytes = 1024 * 1024 ; // 1MB
519
521
uint64_t id = next_id_.fetch_add (1 );
520
522
521
523
for (const auto & si : spatial_indexes) {
@@ -537,6 +539,13 @@ class SpatialDBImpl : public SpatialDB {
537
539
&key, GetQuadKeyFromTile (x, y, spatial_index.tile_bits ));
538
540
PutFixed64BigEndian (&key, id);
539
541
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
+ }
540
549
}
541
550
}
542
551
}
@@ -553,6 +562,7 @@ class SpatialDBImpl : public SpatialDB {
553
562
}
554
563
555
564
virtual Status Compact () override {
565
+ // TODO(icanadi) maybe do this in parallel?
556
566
Status s, t;
557
567
for (auto & iter : name_to_index_) {
558
568
t = Flush (FlushOptions (), iter.second .column_family );
@@ -625,15 +635,20 @@ class SpatialDBImpl : public SpatialDB {
625
635
namespace {
626
636
DBOptions GetDBOptions (const SpatialDBOptions& options) {
627
637
DBOptions db_options;
638
+ db_options.max_open_files = 50000 ;
628
639
db_options.max_background_compactions = 3 * options.num_threads / 4 ;
629
640
db_options.max_background_flushes =
630
641
options.num_threads - db_options.max_background_compactions ;
631
642
db_options.env ->SetBackgroundThreads (db_options.max_background_compactions ,
632
643
Env::LOW);
633
644
db_options.env ->SetBackgroundThreads (db_options.max_background_flushes ,
634
645
Env::HIGH);
646
+ db_options.statistics = CreateDBStatistics ();
635
647
if (options.bulk_load ) {
648
+ db_options.stats_dump_period_sec = 600 ;
636
649
db_options.disableDataSync = true ;
650
+ } else {
651
+ db_options.stats_dump_period_sec = 1800 ; // 30min
637
652
}
638
653
return db_options;
639
654
}
@@ -643,6 +658,8 @@ ColumnFamilyOptions GetColumnFamilyOptions(const SpatialDBOptions& options,
643
658
ColumnFamilyOptions column_family_options;
644
659
column_family_options.write_buffer_size = 128 * 1024 * 1024 ; // 128MB
645
660
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
646
663
column_family_options.level0_file_num_compaction_trigger = 2 ;
647
664
column_family_options.level0_slowdown_writes_trigger = 16 ;
648
665
column_family_options.level0_slowdown_writes_trigger = 32 ;
0 commit comments