Storage Engine API
mobile_recovery_unit.h
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include <memory>
32 #include <string>
33 #include <vector>
34 
35 #include "mongo/base/checked_cast.h"
36 #include "mongo/db/operation_context.h"
37 #include "mongo/db/record_id.h"
42 #include "mongo/platform/atomic_word.h"
43 
44 namespace mongo {
45 
46 class SortedDataInterface;
47 
48 class MobileRecoveryUnit final : public RecoveryUnit {
49 public:
51  virtual ~MobileRecoveryUnit();
52 
53  void beginUnitOfWork(OperationContext* opCtx) override;
54  void commitUnitOfWork() override;
55  void abortUnitOfWork() override;
56 
57  bool waitUntilDurable() override {
58  return true;
59  }
60 
61  void abandonSnapshot() override;
62 
63  void registerChange(Change* change) override;
64 
65  void* writingPtr(void* data, size_t len) override {
66  MONGO_UNREACHABLE;
67  }
68 
69  void setRollbackWritesDisabled() override {}
70 
71  SnapshotId getSnapshotId() const override {
72  return SnapshotId();
73  }
74 
75  MobileSession* getSession(OperationContext* opCtx, bool readOnly = true);
76 
77  MobileSession* getSessionNoTxn(OperationContext* opCtx);
78 
79  bool inActiveTxn() const {
80  return _active;
81  }
82 
83  void assertInActiveTxn() const;
84 
85  void enqueueFailedDrop(std::string& dropQuery);
86 
87  static MobileRecoveryUnit* get(OperationContext* opCtx) {
88  return checked_cast<MobileRecoveryUnit*>(opCtx->recoveryUnit());
89  }
90 
91  void setOrderedCommit(bool orderedCommit) override {}
92 
93 private:
94  void _abort();
95  void _commit();
96 
97  void _ensureSession(OperationContext* opCtx);
98  void _txnClose(bool commit);
99  void _txnOpen(OperationContext* opCtx, bool readOnly);
100  void _upgradeToWriteSession(OperationContext* opCtx);
101 
104  bool _active;
105 
106  static AtomicInt64 _nextID;
107  uint64_t _id;
109 
110  std::string _path;
112  std::unique_ptr<MobileSession> _session;
113 
114  using Changes = std::vector<std::unique_ptr<Change>>;
116 };
117 
118 } // namespace mongo
void beginUnitOfWork(OperationContext *opCtx) override
Marks the beginning of a unit of work.
Definition: mobile_recovery_unit.cpp:93
void _upgradeToWriteSession(OperationContext *opCtx)
Changes _changes
Definition: mobile_recovery_unit.h:115
void * writingPtr(void *data, size_t len) override
Declare that the data at [x, x + len) is being written.
Definition: mobile_recovery_unit.h:65
void commitUnitOfWork() override
Marks the end of a unit of work and commits all changes registered by calls to onCommit or registerCh...
Definition: mobile_recovery_unit.cpp:110
bool waitUntilDurable() override
Waits until all commits that happened before this call are durable in the journal.
Definition: mobile_recovery_unit.h:57
std::unique_ptr< MobileSession > _session
Definition: mobile_recovery_unit.h:112
void setRollbackWritesDisabled() override
Sets a flag that declares this RecoveryUnit will skip rolling back writes, for the duration of the cu...
Definition: mobile_recovery_unit.h:69
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
bool _areWriteUnitOfWorksBanned
Definition: mobile_recovery_unit.h:102
MobileSession * getSession(OperationContext *opCtx, bool readOnly=true)
Definition: mobile_recovery_unit.cpp:142
Definition: mobile_recovery_unit.h:48
SnapshotId getSnapshotId() const override
Gets the local SnapshotId.
Definition: mobile_recovery_unit.h:71
void _txnOpen(OperationContext *opCtx, bool readOnly)
Definition: mobile_recovery_unit.cpp:169
std::string _path
Definition: mobile_recovery_unit.h:110
void abandonSnapshot() override
If there is an open transaction, it is closed.
Definition: mobile_recovery_unit.cpp:128
void assertInActiveTxn() const
Definition: mobile_recovery_unit.cpp:158
std::shared_ptr< void > data
Definition: ephemeral_for_test_record_store_test.cpp:74
uint64_t _id
Definition: mobile_recovery_unit.h:107
void _txnClose(bool commit)
Definition: mobile_recovery_unit.cpp:207
void registerChange(Change *change) override
The RecoveryUnit takes ownership of the change.
Definition: mobile_recovery_unit.cpp:137
std::vector< std::unique_ptr< Change > > Changes
Definition: mobile_recovery_unit.h:114
bool _inUnitOfWork
Definition: mobile_recovery_unit.h:103
void enqueueFailedDrop(std::string &dropQuery)
Definition: mobile_recovery_unit.cpp:221
This class manages a SQLite database connection object.
Definition: mobile_session.h:43
void setOrderedCommit(bool orderedCommit) override
Definition: mobile_recovery_unit.h:91
bool inActiveTxn() const
Definition: mobile_recovery_unit.h:79
A RecoveryUnit is responsible for ensuring that data is persisted.
Definition: recovery_unit.h:51
void _commit()
Definition: mobile_recovery_unit.cpp:63
MobileSessionPool * _sessionPool
Definition: mobile_recovery_unit.h:111
bool _isReadOnly
Definition: mobile_recovery_unit.h:108
virtual ~MobileRecoveryUnit()
Definition: mobile_recovery_unit.cpp:57
void abortUnitOfWork() override
Marks the end of a unit of work and rolls back all changes registered by calls to onRollback or regis...
Definition: mobile_recovery_unit.cpp:119
This class manages a pool of open sqlite3* objects.
Definition: mobile_session_pool.h:66
MobileSession * getSessionNoTxn(OperationContext *opCtx)
Definition: mobile_recovery_unit.cpp:153
Definition: snapshot.h:37
void _ensureSession(OperationContext *opCtx)
Definition: mobile_recovery_unit.cpp:162
void _abort()
Definition: mobile_recovery_unit.cpp:78
static MobileRecoveryUnit * get(OperationContext *opCtx)
Definition: mobile_recovery_unit.h:87
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
bool _active
Definition: mobile_recovery_unit.h:104
MobileRecoveryUnit(MobileSessionPool *sessionPool)
Definition: mobile_recovery_unit.cpp:49
static AtomicInt64 _nextID
Definition: mobile_recovery_unit.h:106