Commit Graph

117 Commits (09ff73b9a728580290b782419771e747c275c8e4)

Author SHA1 Message Date
Benjamin Wang 7b031d53c9 add test case to verify freelist in case of TXN rollback
Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
2024-07-22 14:17:46 +01:00
Thomas Jungblut 62e81c036f introduce a freelist interface
This introduces an interface for the freelist, splits it into two concrete
implementations.

fixes etcd-io#773

Signed-off-by: Thomas Jungblut <tjungblu@redhat.com>
2024-07-09 10:41:35 +02:00
Ivan Valdes fbea5d610d
*: skip logging if logger is discardLogger
If there is no logger defined (discardLogger), skip logging altogether for
highly frequent called methods (Put, Delete, CreateBucket,
CreateBucketIfNotExists, DeleteBucket, Begin, Commit, Open, MoveBucket, Sync).

Signed-off-by: Ivan Valdes <ivan@vald.es>
2024-04-30 06:16:37 -07:00
Benjamin Wang 019c34e51f add method Inspect to inspect bucket structure
Also added a related command: bbolt inspect db

The outputed etcd data structure:
{
    "name": "root",
    "keyN": 0,
    "children": [
        {
            "name": "alarm",
            "keyN": 0
        },
        {
            "name": "auth",
            "keyN": 2
        },
        {
            "name": "authRoles",
            "keyN": 1
        },
        {
            "name": "authUsers",
            "keyN": 1
        },
        {
            "name": "cluster",
            "keyN": 1
        },
        {
            "name": "key",
            "keyN": 1285
        },
        {
            "name": "lease",
            "keyN": 2
        },
        {
            "name": "members",
            "keyN": 1
        },
        {
            "name": "members_removed",
            "keyN": 0
        },
        {
            "name": "meta",
            "keyN": 3
        }
    ]
}

Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
2024-01-11 15:09:58 +00:00
Benjamin Wang 27ded38c22 add MoveBucket to support moving a sub-bucket from one bucket to another bucket
Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
2024-01-02 14:33:00 +01:00
Benjamin Wang 4c7075efe6 add log messages
Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
2023-12-29 11:25:43 +00:00
caojiamingalan 5ce15f0a8a add tx.ID() in log. Change the position of log. If we call tx.ID() before testing the nullity of tx.db, it may panic.
Signed-off-by: caojiamingalan <alan.c.19971111@gmail.com>
2023-11-27 17:26:26 +01:00
caojiamingalan 7d93161fbd add logger
Signed-off-by: caojiamingalan <alan.c.19971111@gmail.com>
2023-11-27 17:08:16 +01:00
Wei Fu 445a07b6cb tx.go: introduce failpoint before fdatasync
It can be used for power failure cases.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2023-11-26 21:26:30 +08:00
Marcondes Viana 5ddbd0c94e tests: add failpoint to simulate lack of disk space
Signed-off-by: Marcondes Viana <marju10@gmail.com>
2023-07-31 08:23:01 -03:00
Cenk Alti daff030646
Update Tx.Commit documentation
Signed-off-by: Cenk Alti <cenkalti@gmail.com>
2023-05-16 14:56:40 -04:00
Cenk Alti 6c836cbcaf
Fix deprecated comment.
Correct way of marking a method deprecated is adding a paragraph that
starts with "Deprecated:".

https://go.dev/blog/godoc
ff3aefbad4/src/cmd/api/api.go (L1137)

Signed-off-by: Cenk Alti <cenkalti@gmail.com>
2023-05-15 16:01:11 -04:00
Josh Rickmar 7a957f94b2 Introduce errors package and restore API compatibility
This moves the error variables that had been moved to the
internal/common package during recent refactoring to a non-internal
errors package, once again allowing consumers to test for particular
error conditions.

To preserve API compatibility with bbolt v1.3, these error variables
are also redefined in the bbolt package, with deprecation notice to
migrate to bbolt/errors.

Signed-off-by: Josh Rickmar <jrick@zettaport.com>
2023-04-06 13:26:30 +00:00
Benjamin Wang a3a9877de6 encapsulate the logic of checking the page type
Signed-off-by: Benjamin Wang <wachao@vmware.com>
2023-03-08 10:47:59 +08:00
Benjamin Wang ea511567eb refactor both bolt and guts_cli based on the common package
Signed-off-by: Benjamin Wang <wachao@vmware.com>
2023-03-04 04:22:09 +08:00
Benjamin Wang 35c4569bf9 revert the signature of tx.Check and add tx.CheckWithStringer
Signed-off-by: Benjamin Wang <wachao@vmware.com>
2023-01-29 19:53:07 +08:00
luv 460b77759e fix db.grow is unusable when NoFreelistSync is on
Signed-off-by: tian <skylypig@gmail.com>
2023-01-19 22:33:51 +08:00
Piotr Tabor 51370e425a
Merge pull request #225 from ptabor/extend_checker2
Recursive checker implementation.
2023-01-14 12:03:10 +01:00
Piotr Tabor f16e2522ce Address review comments.
Signed-off-by: Piotr Tabor <ptab@google.com>
2023-01-13 19:14:45 +01:00
Piotr Tabor 0c8d75db1e Recursive checker implementation.
Recursive checker confirms database consistency with respect to b-tree
key order constraints:
  - keys on pages must be sorted
  - keys on children pages are between 2 consecutive keys on parent
branch page).

Signed-off-by: Piotr Tabor <ptab@google.com>
2023-01-13 19:14:45 +01:00
Piotr Tabor 0ccb16dc02 Mechanical move of Check functions to tx_check.go file.
Signed-off-by: Piotr Tabor <ptab@google.com>
2023-01-13 19:14:45 +01:00
Benjamin Wang eabffad75a add protection when mmap somehow fails
Signed-off-by: Benjamin Wang <wachao@vmware.com>
2023-01-12 07:58:02 +08:00
Benjamin Wang d2fae80500 add protection on (*Tx)Page method in case free pages are not preloaded
Signed-off-by: Benjamin Wang <wachao@vmware.com>
2023-01-11 18:39:32 +08:00
Benjamin Wang 6bc57389f0 add PreLoadFreelist to support loading free pages in readonly mode
Signed-off-by: Benjamin Wang <wachao@vmware.com>
2023-01-11 18:10:12 +08:00
Wei Fu c99164bcd9 TxStats: add DEPRECATED comments for exported fields
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2023-01-05 10:31:00 +08:00
Wei Fu dd4458ce3a TxStats: provides Getter/Inc functions
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2023-01-04 20:06:51 +08:00
Wei Fu 27ac0b8958 fix data race on tx.Stats
Fixes: #213

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2023-01-02 22:29:43 +08:00
Piotr Tabor d1aa8034d4 Validate page being fetched at possition 'p' self identifies as page 'p'.
It's the easiest verification whether the page is actually written, or its 'random' garbage in the block.

Signed-off-by: Piotr Tabor <ptab@google.com>
2022-12-23 09:37:41 +01:00
Piotr Tabor ebca452da7 Add internal iterator to Bucket that goes over buckets.
So far the code was frequently traversing all the keys (ignoring flag whether key is a bucket)
and trying to open each of the keys as bucket (seeking the same entry from the scratch).

In this proposal, we iterate only through bucket keys.

Signed-off-by: Piotr Tabor <ptab@google.com>
2022-12-21 12:16:50 +01:00
Piotr Tabor 7190a8fe57 Pages stacktrace should be provided for initialization errors.
It makes it easy to find which page actually looks to be corrupted.
```
go build ./cmd/bbolt/ && ./bbolt check ~/Downloads/db
panic: freepages: failed to get all reachable pages (page 8314893338927566090: out of bounds: 6258 (stack: [4517 395 821]))

goroutine 18 [running]:
go.etcd.io/bbolt.(*DB).freepages.func2()
        /Users/ptab/gits/bbolt/db.go:1056 +0x8c
created by go.etcd.io/bbolt.(*DB).freepages
        /Users/ptab/gits/bbolt/db.go:1054 +0x138
```

Signed-off-by: Piotr Tabor <ptab@google.com>
2022-12-17 15:32:54 +01:00
Manuel Rüger 33c86c78ca .github: Enable lint
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
2022-10-20 22:47:35 +02:00
Makdon 8c171443bc
tx: remove outdated comment (#271)
After commit #37e96de, it reports errs in the panic

Co-authored-by: makdonmai(麦栋铖) <makdonmai@wesure.cn>
2021-04-16 14:42:49 -07:00
zounengren cc6381f7d5 Use WriteTo() instead 2021-03-16 15:59:07 +08:00
Josh Rickmar f9d3ff6648 Fix incorrect unsafe usage
After checkptr fixes by 2fc6815c, it was discovered that new issues
were hit in production systems, in particular when a single process
opened and updated multiple separate databases.  This indicates that
some bug relating to bad unsafe usage was introduced during this
commit.

This commit combines several attempts at fixing this new issue.  For
example, slices are once again created by slicing an array of "max
allocation" elements, but this time with the cap set to the intended
length.  This operation is espressly permitted according to the Go
wiki, so it should be preferred to type converting a
reflect.SliceHeader.
2020-04-28 20:30:23 +00:00
Josh Rickmar 543c40ab41 Fix unsafe pointer conversions caught by Go 1.14 checkptr 2020-03-18 21:18:39 -04:00
Xingyu Chen a0458a2b35 fix rollback panic bug (#153) 2019-06-08 09:57:04 -07:00
Tom Payne 4af6cfab70 add OpenFile option (#158) 2019-05-10 14:16:40 -07:00
Gyuho Lee 76a4670663 *: update import paths "go.etcd.io/bbolt"
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
2018-08-28 08:15:54 -07:00
Chyroc 32f8e5fee9 add tx-copy-deprecated 2018-03-17 00:58:22 -07:00
zhesi.huang 22635d7451 tx: fix the number of pages is not incorrectly counted 2017-11-12 08:40:47 +08:00
Anthony Romano bdfe4158f8 tx: load freelist on Check()
Otherwise, nil dereference on ReadOnly DB

Fixes #45
2017-09-21 16:38:29 -07:00
Anthony Romano 27600282c6 Merge pull request #44 from lorneli/bbolt_tx
tx: just close file once in WriteTo function
2017-09-14 00:21:27 -07:00
lorneli 53a930f1e1 tx: just close file once in WriteTo function
WriteTo function closes file twice in normal path previously.
2017-09-13 17:48:18 +08:00
lorneli 4ce1b5e579 tx: use io.SeekStart in WriteTo function
Const os.SEEK_SET is deprecated.
2017-09-11 12:53:41 +08:00
Anthony Romano e5514a24a6 pass gosimple 2017-08-10 22:07:25 -07:00
Anthony Romano fd5de8495a fix NoSyncFreelist reachability checking
* unconditionally free freelist, if any, when committing txn

* only treat freelist pages as reachable if set to valid pgid

Fixes #9
2017-08-09 07:24:02 -07:00
Anthony Romano 05bfb3bd9a rebuild freelist when opening with FreelistSync after NoFreelistSync
Writes pgidNoFreelist to the meta freelist page to detect when freelists
haven't been synced down.

Fixes #5
2017-07-25 08:01:43 -07:00
Xiang Li ad39960eb4 Merge pull request #3 from heyitsanthony/range-gc
Garbage collect pages allocated after minimum txid
2017-06-23 18:19:54 -07:00
Xiang 7149270521 *: add option to skip freelist sync
When the database has a lot of freepages, the cost to sync all
freepages down to disk is high. If the total database size is
small (<10GB), and the application can tolerate ~10 seconds
recovery time, then it is reasonable to simply not sync freelist
and rescan the db to rebuild freelist on recovery.
2017-06-22 12:46:56 -07:00
Anthony Romano 78d099ed1f Garbage collect pages allocated after minimum txid
Read txns would lock pages allocated after the txn, keeping those pages
off the free list until closing the read txn. Instead, track allocating
txid to compute page lifetime, freeing pages if all txns between
page allocation and page free are closed.
2017-06-05 16:07:55 -07:00