1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
19 #include "db/column_family.h"
20 #include "db/dbformat.h"
21 #include "db/flush_scheduler.h"
22 #include "db/internal_stats.h"
23 #include "db/job_context.h"
24 #include "db/log_writer.h"
25 #include "db/logs_with_prep_tracker.h"
26 #include "db/memtable_list.h"
27 #include "db/snapshot_impl.h"
28 #include "db/version_edit.h"
29 #include "db/write_controller.h"
30 #include "db/write_thread.h"
31 #include "monitoring/instrumented_mutex.h"
32 #include "options/db_options.h"
33 #include "port/port.h"
34 #include "rocksdb/db.h"
35 #include "rocksdb/env.h"
36 #include "rocksdb/memtablerep.h"
37 #include "rocksdb/transaction_log.h"
38 #include "table/scoped_arena_iterator.h"
39 #include "util/autovector.h"
40 #include "util/event_logger.h"
41 #include "util/stop_watch.h"
42 #include "util/thread_local.h"
48 class SnapshotChecker
;
57 // TODO(icanadi) make effort to reduce number of parameters here
58 // IMPORTANT: mutable_cf_options needs to be alive while FlushJob is alive
59 FlushJob(const std::string
& dbname
, ColumnFamilyData
* cfd
,
60 const ImmutableDBOptions
& db_options
,
61 const MutableCFOptions
& mutable_cf_options
,
62 const EnvOptions env_options
, VersionSet
* versions
,
63 InstrumentedMutex
* db_mutex
, std::atomic
<bool>* shutting_down
,
64 std::vector
<SequenceNumber
> existing_snapshots
,
65 SequenceNumber earliest_write_conflict_snapshot
,
66 SnapshotChecker
* snapshot_checker
, JobContext
* job_context
,
67 LogBuffer
* log_buffer
, Directory
* db_directory
,
68 Directory
* output_file_directory
, CompressionType output_compression
,
69 Statistics
* stats
, EventLogger
* event_logger
, bool measure_io_stats
);
73 // Require db_mutex held.
74 // Once PickMemTable() is called, either Run() or Cancel() has to be called.
76 Status
Run(LogsWithPrepTracker
* prep_tracker
= nullptr,
77 FileMetaData
* file_meta
= nullptr);
79 TableProperties
GetTableProperties() const { return table_properties_
; }
82 void ReportStartedFlush();
83 void ReportFlushInputSize(const autovector
<MemTable
*>& mems
);
84 void RecordFlushIOStats();
85 Status
WriteLevel0Table();
86 const std::string
& dbname_
;
87 ColumnFamilyData
* cfd_
;
88 const ImmutableDBOptions
& db_options_
;
89 const MutableCFOptions
& mutable_cf_options_
;
90 const EnvOptions env_options_
;
91 VersionSet
* versions_
;
92 InstrumentedMutex
* db_mutex_
;
93 std::atomic
<bool>* shutting_down_
;
94 std::vector
<SequenceNumber
> existing_snapshots_
;
95 SequenceNumber earliest_write_conflict_snapshot_
;
96 SnapshotChecker
* snapshot_checker_
;
97 JobContext
* job_context_
;
98 LogBuffer
* log_buffer_
;
99 Directory
* db_directory_
;
100 Directory
* output_file_directory_
;
101 CompressionType output_compression_
;
103 EventLogger
* event_logger_
;
104 TableProperties table_properties_
;
105 bool measure_io_stats_
;
107 // Variables below are set by PickMemTable():
109 autovector
<MemTable
*> mems_
;
112 bool pick_memtable_called
;
115 } // namespace rocksdb