Storage Engine API
wiredtiger_oplog_manager.h
Go to the documentation of this file.
1 
30 #pragma once
31 
32 #include "mongo/base/disallow_copying.h"
34 #include "mongo/stdx/condition_variable.h"
35 #include "mongo/stdx/mutex.h"
36 #include "mongo/stdx/thread.h"
37 #include "mongo/util/concurrency/with_lock.h"
38 
39 namespace mongo {
40 
41 class WiredTigerRecordStore;
42 class WiredTigerSessionCache;
43 
44 
45 // Manages oplog visibility, by periodically querying WiredTiger's all_committed timestamp value and
46 // then using that timestamp for all transactions that read the oplog collection.
49 
50 public:
53 
54  // This method will initialize the oplog read timestamp and start the background thread that
55  // refreshes the value.
56  void start(OperationContext* opCtx,
57  const std::string& uri,
58  WiredTigerRecordStore* oplogRecordStore);
59 
60  void halt();
61 
62  bool isRunning() {
63  stdx::lock_guard<stdx::mutex> lk(_oplogVisibilityStateMutex);
64  return _isRunning && !_shuttingDown;
65  }
66 
67  // The oplogReadTimestamp is the timestamp used for oplog reads, to prevent readers from
68  // reading past uncommitted transactions (which may create "holes" in the oplog after an
69  // unclean shutdown).
70  std::uint64_t getOplogReadTimestamp() const;
71  void setOplogReadTimestamp(Timestamp ts);
72 
73  // Triggers the oplogJournal thread to update its oplog read timestamp, by flushing the journal.
74  void triggerJournalFlush();
75 
76  // Waits until all committed writes at this point to become visible (that is, no holes exist in
77  // the oplog.)
79  OperationContext* opCtx) const;
80 
81  // Returns the all committed timestamp. All transactions with timestamps earlier than the
82  // all committed timestamp are committed.
83  uint64_t fetchAllCommittedValue(WT_CONNECTION* conn);
84 
85 private:
87  WiredTigerRecordStore* oplogRecordStore) noexcept;
88 
89  void _setOplogReadTimestamp(WithLock, uint64_t newTimestamp);
90 
91  stdx::thread _oplogJournalThread;
92  mutable stdx::mutex _oplogVisibilityStateMutex;
93  mutable stdx::condition_variable
94  _opsWaitingForJournalCV; // Signaled to trigger a journal flush.
95  mutable stdx::condition_variable
96  _opsBecameVisibleCV; // Signaled when a journal flush is complete.
97 
98  bool _isRunning = false; // Guarded by the oplogVisibilityStateMutex.
99  bool _shuttingDown = false; // Guarded by oplogVisibilityStateMutex.
100 
101  // This is the RecordId of the newest oplog document in the oplog on startup. It is used as a
102  // floor in waitForAllEarlierOplogWritesToBeVisible().
103  RecordId _oplogMaxAtStartup = RecordId(0); // Guarded by oplogVisibilityStateMutex.
104  bool _opsWaitingForJournal = false; // Guarded by oplogVisibilityStateMutex.
105 
106  AtomicUInt64 _oplogReadTimestamp;
107 };
108 } // namespace mongo
void setOplogReadTimestamp(Timestamp ts)
Definition: wiredtiger_oplog_manager.cpp:241
Definition: wiredtiger_record_store.h:73
RecordId _oplogMaxAtStartup
Definition: wiredtiger_oplog_manager.h:103
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
stdx::condition_variable _opsBecameVisibleCV
Definition: wiredtiger_oplog_manager.h:96
stdx::condition_variable _opsWaitingForJournalCV
Definition: wiredtiger_oplog_manager.h:94
bool _opsWaitingForJournal
Definition: wiredtiger_oplog_manager.h:104
bool isRunning()
Definition: wiredtiger_oplog_manager.h:62
void halt()
Definition: wiredtiger_oplog_manager.cpp:88
stdx::mutex _oplogVisibilityStateMutex
Definition: wiredtiger_oplog_manager.h:92
std::uint64_t getOplogReadTimestamp() const
Definition: wiredtiger_oplog_manager.cpp:237
bool _isRunning
Definition: wiredtiger_oplog_manager.h:98
void waitForAllEarlierOplogWritesToBeVisible(const WiredTigerRecordStore *oplogRecordStore, OperationContext *opCtx) const
Definition: wiredtiger_oplog_manager.cpp:102
Definition: wiredtiger_oplog_manager.h:47
MONGO_DISALLOW_COPYING(WiredTigerOplogManager)
WiredTigerOplogManager()
Definition: wiredtiger_oplog_manager.h:51
stdx::thread _oplogJournalThread
Definition: wiredtiger_oplog_manager.h:91
AtomicUInt64 _oplogReadTimestamp
Definition: wiredtiger_oplog_manager.h:106
void start(OperationContext *opCtx, const std::string &uri, WiredTigerRecordStore *oplogRecordStore)
Definition: wiredtiger_oplog_manager.cpp:52
void _setOplogReadTimestamp(WithLock, uint64_t newTimestamp)
Definition: wiredtiger_oplog_manager.cpp:246
~WiredTigerOplogManager()
Definition: wiredtiger_oplog_manager.h:52
void _oplogJournalThreadLoop(WiredTigerSessionCache *sessionCache, WiredTigerRecordStore *oplogRecordStore) noexcept
Definition: wiredtiger_oplog_manager.cpp:157
uint64_t fetchAllCommittedValue(WT_CONNECTION *conn)
Definition: wiredtiger_oplog_manager.cpp:252
This cache implements a shared pool of WiredTiger sessions with the goal to amortize the cost of sess...
Definition: wiredtiger_session_cache.h:156
void triggerJournalFlush()
Definition: wiredtiger_oplog_manager.cpp:149
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
std::string uri
Definition: wiredtiger_standard_record_store_test.cpp:367
bool _shuttingDown
Definition: wiredtiger_oplog_manager.h:99