Storage Engine API
deferred_writer.h
Go to the documentation of this file.
1 
29 #pragma once
30 
32 #include "mongo/db/namespace_string.h"
33 #include "mongo/db/operation_context.h"
34 #include "mongo/stdx/mutex.h"
35 
36 namespace mongo {
37 
38 class AutoGetCollection;
39 class ThreadPool;
40 
60 
61 public:
70  DeferredWriter(NamespaceString nss, CollectionOptions opts, int64_t maxSize);
71 
77  void startup(std::string workerName);
78 
86  void shutdown(void);
87 
95 
103  bool insertDocument(BSONObj obj);
104 
108  int64_t getDroppedEntries();
109 
110 private:
114  void _logFailure(const Status& status);
115 
120  void _logDroppedEntry();
121 
127  Status _makeCollection(OperationContext* opCtx);
128 
133 
137  void _worker(InsertStatement stmt);
138 
143 
147  const int64_t _maxNumBytes;
148 
152  const NamespaceString _nss;
153 
154  std::unique_ptr<ThreadPool> _pool;
155 
159  stdx::mutex _mutex;
160 
164  int64_t _numBytes;
165 
171 
177  using TimePoint = stdx::chrono::time_point<stdx::chrono::system_clock>;
180 };
181 
182 } // namespace mongo
TimePoint _lastLoggedDrop
Definition: deferred_writer.h:179
StatusWith< std::unique_ptr< AutoGetCollection > > _getCollection(OperationContext *opCtx)
Ensure that the backing collection exists, and pass back a lock and handle to it. ...
Definition: deferred_writer.cpp:75
int64_t _numBytes
The number of bytes currently in the in-memory buffer.
Definition: deferred_writer.h:164
int64_t _droppedEntries
The number of deffered entries that have been dropped.
Definition: deferred_writer.h:170
stdx::mutex _mutex
Guards all non-const, non-thread-safe members.
Definition: deferred_writer.h:159
~DeferredWriter()
Cleans up the writer.
Definition: deferred_writer.cpp:138
Definition: collection_options.h:57
void shutdown(void)
Flush the buffer and join the worker thread.
Definition: deferred_writer.cpp:153
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
void _logDroppedEntry()
Log number of entries dropped because of a full buffer.
Definition: deferred_writer.cpp:54
Provides an interface for asynchronously adding to a collection.
Definition: deferred_writer.h:58
OperationContext Database StringData BSONObj CollectionOptions::ParseKind bool const BSONObj &idIndex Status
Definition: database_impl.cpp:956
const CollectionOptions _collectionOptions
The options for the collection, in case we need to create it.
Definition: deferred_writer.h:142
int64_t getDroppedEntries()
Get the number of dropped writes due to a full buffer since the last log.
Definition: deferred_writer.cpp:184
void _logFailure(const Status &status)
Log failure, but only if a certain interval has passed since the last log.
Definition: deferred_writer.cpp:47
const int64_t _maxNumBytes
The size limit of the in-memory buffer.
Definition: deferred_writer.h:147
Status status
Definition: database_impl.cpp:975
TimePoint _lastLogged
Definition: deferred_writer.h:178
Definition: index_key_validate.h:40
void startup(std::string workerName)
Start the background worker thread writing to the given collection.
Definition: deferred_writer.cpp:140
Status _makeCollection(OperationContext *opCtx)
Create the backing collection if it doesn&#39;t exist.
Definition: deferred_writer.cpp:64
stdx::chrono::time_point< stdx::chrono::system_clock > TimePoint
Time we last logged that we can&#39;t write to the underlying collection.
Definition: deferred_writer.h:177
MONGO_DISALLOW_COPYING(DeferredWriter)
const NamespaceString _nss
The name of the backing collection.
Definition: deferred_writer.h:152
void _worker(InsertStatement stmt)
The method that the worker thread will run.
Definition: deferred_writer.cpp:95
bool insertDocument(BSONObj obj)
Deferred-insert the given object.
Definition: deferred_writer.cpp:164
DeferredWriter(NamespaceString nss, CollectionOptions opts, int64_t maxSize)
Create a new DeferredWriter for writing to a given collection.
Definition: deferred_writer.cpp:130
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
std::unique_ptr< ThreadPool > _pool
Definition: deferred_writer.h:154