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 
43 namespace mongo {
44 
45 class SortedDataInterface;
46 
47 class MobileRecoveryUnit final : public RecoveryUnit {
48 public:
50  virtual ~MobileRecoveryUnit();
51 
52  void beginUnitOfWork(OperationContext* opCtx) override;
53  void commitUnitOfWork() override;
54  void abortUnitOfWork() override;
55 
56  bool waitUntilDurable() override {
57  return true;
58  }
59 
60  void abandonSnapshot() override;
61 
62  void registerChange(Change* change) override;
63 
64  void* writingPtr(void* data, size_t len) override {
65  MONGO_UNREACHABLE;
66  }
67 
68  void setRollbackWritesDisabled() override {}
69 
70  SnapshotId getSnapshotId() const override {
71  return SnapshotId();
72  }
73 
74  MobileSession* getSession(OperationContext* opCtx);
75 
76  MobileSession* getSessionNoTxn(OperationContext* opCtx);
77 
78  bool inActiveTxn() const {
79  return _active;
80  }
81 
82  void assertInActiveTxn() const;
83 
84  void enqueueFailedDrop(std::string& dropQuery);
85 
86  static MobileRecoveryUnit* get(OperationContext* opCtx) {
87  return checked_cast<MobileRecoveryUnit*>(opCtx->recoveryUnit());
88  }
89 
90  void setOrderedCommit(bool orderedCommit) override {}
91 
92 private:
93  void _abort();
94  void _commit();
95 
96  void _ensureSession(OperationContext* opCtx);
97  void _txnClose(bool commit);
98  void _txnOpen(OperationContext* opCtx);
99 
102  bool _active;
103 
104  std::string _path;
106  std::unique_ptr<MobileSession> _session;
107 
108  using Changes = std::vector<std::unique_ptr<Change>>;
110 };
111 
112 } // namespace mongo
MobileSession * getSession(OperationContext *opCtx)
Definition: mobile_recovery_unit.cpp:111
void beginUnitOfWork(OperationContext *opCtx) override
Marks the beginning of a unit of work.
Definition: mobile_recovery_unit.cpp:79
Changes _changes
Definition: mobile_recovery_unit.h:109
void * writingPtr(void *data, size_t len) override
Declare that the data at [x, x + len) is being written.
Definition: mobile_recovery_unit.h:64
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:85
bool waitUntilDurable() override
Waits until all commits that happened before this call are durable in the journal.
Definition: mobile_recovery_unit.h:56
std::unique_ptr< MobileSession > _session
Definition: mobile_recovery_unit.h:106
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:68
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
bool _areWriteUnitOfWorksBanned
Definition: mobile_recovery_unit.h:100
Definition: mobile_recovery_unit.h:47
SnapshotId getSnapshotId() const override
Gets the local SnapshotId.
Definition: mobile_recovery_unit.h:70
std::string _path
Definition: mobile_recovery_unit.h:104
void abandonSnapshot() override
If there is an open transaction, it is closed.
Definition: mobile_recovery_unit.cpp:97
void assertInActiveTxn() const
Definition: mobile_recovery_unit.cpp:123
std::shared_ptr< void > data
Definition: ephemeral_for_test_record_store_test.cpp:74
void _txnClose(bool commit)
Definition: mobile_recovery_unit.cpp:151
void registerChange(Change *change) override
The RecoveryUnit takes ownership of the change.
Definition: mobile_recovery_unit.cpp:106
std::vector< std::unique_ptr< Change > > Changes
Definition: mobile_recovery_unit.h:108
bool _inUnitOfWork
Definition: mobile_recovery_unit.h:101
void enqueueFailedDrop(std::string &dropQuery)
Definition: mobile_recovery_unit.cpp:163
This class manages a SQLite database connection object.
Definition: mobile_session.h:43
void setOrderedCommit(bool orderedCommit) override
Definition: mobile_recovery_unit.h:90
bool inActiveTxn() const
Definition: mobile_recovery_unit.h:78
A RecoveryUnit is responsible for ensuring that data is persisted.
Definition: recovery_unit.h:51
void _commit()
Definition: mobile_recovery_unit.cpp:49
MobileSessionPool * _sessionPool
Definition: mobile_recovery_unit.h:105
virtual ~MobileRecoveryUnit()
Definition: mobile_recovery_unit.cpp:44
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:91
This class manages a pool of open sqlite3* objects.
Definition: mobile_session_pool.h:66
A Change is an action that is registerChange()&#39;d while a WriteUnitOfWork exists.
Definition: recovery_unit.h:281
MobileSession * getSessionNoTxn(OperationContext *opCtx)
Definition: mobile_recovery_unit.cpp:118
void _txnOpen(OperationContext *opCtx)
Definition: mobile_recovery_unit.cpp:133
Definition: snapshot.h:37
void _ensureSession(OperationContext *opCtx)
Definition: mobile_recovery_unit.cpp:127
void _abort()
Definition: mobile_recovery_unit.cpp:64
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
bool _active
Definition: mobile_recovery_unit.h:102
MobileRecoveryUnit(MobileSessionPool *sessionPool)
Definition: mobile_recovery_unit.cpp:41