MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / Commit

Method Commit

tx.go:176–300  ·  view source on GitHub ↗

Commit commits the transaction, following these steps: 1. check the length of pendingWrites.If there are no writes, return immediately. 2. check if the ActiveFile has not enough space to store entry. if not, call rotateActiveFile function. 3. write pendingWrites to disk, if a non-nil error,return

()

Source from the content-addressed store, hash-verified

174//
175// 6. Unlock the database and clear the db field.
176func (tx *Tx) Commit() (err error) {
177 defer func() {
178 if err != nil {
179 tx.handleErr(err)
180 }
181
182 tx.unlock()
183
184 // Ensure the transaction is unregistered so active counts stay accurate
185 tx.db.transactionMgr.UnregisterTx(tx.id)
186
187 tx.db = nil
188
189 tx.pendingWrites = nil
190 }()
191
192 if tx.isClosed() {
193 return ErrCannotCommitAClosedTx
194 }
195
196 if tx.db == nil {
197 tx.setStatusClosed()
198 return ErrDBClosed
199 }
200
201 var curWriteCount int64
202
203 // If the database is closing/closed, abort early to avoid touching released resources.
204 if tx.db.statusMgr.isClosed() {
205 return ErrDBClosed
206 }
207
208 if tx.db.opt.MaxWriteRecordCount > 0 {
209 curWriteCount, err = tx.getNewAddRecordCount()
210 if err != nil {
211 return err
212 }
213
214 // judge all write records is whether more than the MaxWriteRecordCount
215 if tx.db.RecordCount+curWriteCount > tx.db.opt.MaxWriteRecordCount {
216 return ErrTxnExceedWriteLimit
217 }
218 }
219
220 tx.setStatusCommitting()
221 defer tx.setStatusClosed()
222
223 writesBucketLen := len(tx.pendingBucketList)
224 if tx.pendingWrites.size == 0 && writesBucketLen == 0 {
225 return nil
226 }
227
228 buff := tx.allocCommitBuffer()
229 defer tx.db.commitBuffer.Reset()
230
231 var records []*core.Record
232
233 pendingWriteList := tx.pendingWrites.toList()

Callers 15

managedMethod · 0.95
TestIsPrefixScanFunction · 0.80
TestIsPrefixSearchScanFunction · 0.80
commitTransactionMethod · 0.80
TestTx_PutAndGetFunction · 0.80
TestTx_GetAfterDeleteFunction · 0.80
TestTx_RangeScan_ErrFunction · 0.80
TestTx_RangeScanFunction · 0.80
TestTx_PrefixScanFunction · 0.80
TestTx_PrefixSearchScanFunction · 0.80
TestTx_DeleteAndGetFunction · 0.80

Calls 15

handleErrMethod · 0.95
unlockMethod · 0.95
isClosedMethod · 0.95
setStatusClosedMethod · 0.95
getNewAddRecordCountMethod · 0.95
setStatusCommittingMethod · 0.95
allocCommitBufferMethod · 0.95
writeDataMethod · 0.95
rotateActiveFileMethod · 0.95
SubmitBucketMethod · 0.95
buildIdxesMethod · 0.95

Tested by 15

TestIsPrefixScanFunction · 0.64
TestIsPrefixSearchScanFunction · 0.64
TestTx_PutAndGetFunction · 0.64
TestTx_GetAfterDeleteFunction · 0.64
TestTx_RangeScan_ErrFunction · 0.64
TestTx_RangeScanFunction · 0.64
TestTx_PrefixScanFunction · 0.64
TestTx_PrefixSearchScanFunction · 0.64
TestTx_DeleteAndGetFunction · 0.64