Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfoxtyler committed Feb 11, 2025
1 parent 7071d25 commit 4ea6b2f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 33 deletions.
14 changes: 7 additions & 7 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: 0.1

cli:
version: 1.22.9
version: 1.22.10

plugins:
sources:
Expand All @@ -18,20 +18,20 @@ runtimes:

lint:
enabled:
- renovate@39.156.1
- renovate@39.164.1
- [email protected]
- [email protected].4
- [email protected].5
- [email protected]
- [email protected].361
- [email protected].369
- git-diff-check
- [email protected]
- [email protected]
- prettier@3.4.2:
- prettier@3.5.0:
packages:
- "@mintlify/[email protected]"
- [email protected]
- [email protected].0
- [email protected].4
- [email protected].1
- [email protected].5
- [email protected]
ignore:
- linters: [ALL]
Expand Down
2 changes: 1 addition & 1 deletion badger/design.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Design
description: "Architected for fast key-value storage in Go"
description: Architected for fast key-value storage in Go
"og:title": "Design - Badger"
---

Expand Down
2 changes: 1 addition & 1 deletion badger/overview.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Overview
description: "Welcome to the Badger docs!"
description: Welcome to the Badger docs!
mode: "wide"
"og:title": "Overview - Badger"
---
Expand Down
39 changes: 21 additions & 18 deletions badger/quickstart.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Quickstart
description: "Everything you need to get started with Badger"
description: Everything you need to get started with Badger
"og:title": "Quickstart - Badger"
---

Expand All @@ -18,7 +18,7 @@ To start using Badger, run the following command to retrieve the library.
go get github.com/dgraph-io/badger/v4
```

Then, install the Badger command line utility into your $GOBIN path.
Then, install the Badger command line utility into your `$GOBIN` path.

```sh
go install github.com/dgraph-io/badger/v4/badger@latest
Expand Down Expand Up @@ -54,30 +54,32 @@ func main() {
if err != nil {
log.Fatal(err)
}

defer db.Close()
// Your code here…

// your code here
}
```

### In-memory/diskless mode

By default, Badger ensures all data persists to disk. It also supports a pure
in-memory mode. When Badger is running in this mode, all data remains in memory
only. Reads and writes are much faster, but all data stored in Badger is lost in
the case of a crash or close. To open badger in in-memory mode, set the
`InMemory` option.
only. Reads and writes are much faster, but Badger loses all stored data in the
case of a crash or close. To open badger in in-memory mode, set the `InMemory`
option.

```go
opt := badger.DefaultOptions("").WithInMemory(true)
```

### Encryption mode

If you enable encryption on Badger, you also need to set the index cache size.
If you enable encryption in Badger, you also need to set the index cache size.

<Tip>
Having a cache improves the performance. Otherwise, your reads would be very
slow while encryption is enabled.
The cache improves the performance. Otherwise, reads can be very slow with
encryption enabled.
</Tip>

For example, to set a `100 Mb` cache:
Expand All @@ -94,7 +96,8 @@ To start a read-only transaction, you can use the `DB.View()` method:

```go
err := db.View(func(txn *badger.Txn) error {
// Your code here…
// your code here

return nil
})
```
Expand All @@ -115,18 +118,18 @@ err := db.Update(func(txn *badger.Txn) error {
})
```

All database operations are allowed inside a read-write transaction.
Badger allows all database operations inside a read-write transaction.

Always check the returned error value. If you return an error within your
closure it will be passed through.
closure it's passed through.

An `ErrConflict` error will be reported in case of a conflict. Depending on the
state of your app, you have the option to retry the operation if you receive
this error.
An `ErrConflict` error is reported in case of a conflict. Depending on the state

Check failure on line 126 in badger/quickstart.mdx

View check run for this annotation

Trunk.io / Trunk Check

vale(error)

[new] In general, use active voice instead of passive voice ('is reported').
of your app, you have the option to retry the operation if you receive this
error.

An `ErrTxnTooBig` will be reported in case the number of pending writes/deletes
in the transaction exceeds a certain limit. In that case, it's best to commit
the transaction and start a new transaction immediately. Here is an example (we
An `ErrTxnTooBig` is reported in case the number of pending writes/deletes in

Check failure on line 130 in badger/quickstart.mdx

View check run for this annotation

Trunk.io / Trunk Check

vale(error)

[new] In general, use active voice instead of passive voice ('is reported').
the transaction exceeds a certain limit. In that case, it's best to commit the
transaction and start a new transaction immediately. Here is an example (we
aren't checking for errors in some places for simplicity):

```go
Expand Down
12 changes: 6 additions & 6 deletions badger/troubleshooting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ description: "Common issues and solutions with Badger"
"og:title": "Troubleshooting - Badger"
---

## My writes are getting stuck
## Writes are getting stuck

**Update: with the new `Value(func(v []byte))` API, this deadlock can no longer
happen.**

The following is true for users on Badger v1.x.

This can happen if a long running iteration with `Prefetch` is set to false, but

Check failure on line 14 in badger/troubleshooting.mdx

View check run for this annotation

Trunk.io / Trunk Check

vale(error)

[new] In general, use active voice instead of passive voice ('is set').
a `Item::Value` call is made internally in the loop. That causes Badger to
an `Item::Value` call is made internally in the loop. That causes Badger to

Check failure on line 15 in badger/troubleshooting.mdx

View check run for this annotation

Trunk.io / Trunk Check

vale(error)

[new] In general, use active voice instead of passive voice ('is made').
acquire read locks over the value log files to avoid value log GC removing the
file from underneath. As a side effect, this also blocks a new value log GC file
from being created, when the value log file boundary is hit.

Check failure on line 18 in badger/troubleshooting.mdx

View check run for this annotation

Trunk.io / Trunk Check

vale(error)

[new] In general, use active voice instead of passive voice ('being created').

Check failure on line 18 in badger/troubleshooting.mdx

View check run for this annotation

Trunk.io / Trunk Check

vale(error)

[new] In general, use active voice instead of passive voice ('is hit').
Expand All @@ -30,7 +30,7 @@ There are multiple workarounds during iteration:
iteration. This might be useful if you just want to delete a lot of keys.
1. Do the writes in a separate transaction after the reads.

## My writes are really slow
## Writes are really slow

Are you creating a new transaction for every single key update, and waiting for
it to `Commit` fully before creating a new one? This leads to very low
Expand Down Expand Up @@ -64,7 +64,7 @@ would only happen once `BaseTableSize` has been reached. So, if you're doing a
few writes and then checking, you might not see anything on disk. Once you
`Close` the database, you'll see these writes on disk.

## Reverse iteration doesn't give me the right results
## Reverse iteration doesn't produce the right results

Just like forward iteration goes to the first key which is equal or greater than
the SEEK key, reverse iteration goes to the first key which is equal or lesser

Check failure on line 70 in badger/troubleshooting.mdx

View check run for this annotation

Trunk.io / Trunk Check

vale(error)

[new] Spell out 'SEEK', if it's unfamiliar to the audience.
Expand Down Expand Up @@ -122,7 +122,7 @@ were on badger v1.6.0 and you wish to migrate to v2.0.0 version.
- `git checkout v1.6.0`
- `cd badger && go install`

This should install the old badger binary in your $GOBIN.
This should install the old badger binary in your `$GOBIN`.

2. Create Backup
- `badger backup --dir path/to/badger/directory -f badger.backup`
Expand All @@ -132,7 +132,7 @@ were on badger v1.6.0 and you wish to migrate to v2.0.0 version.
- `git checkout v2.0.0`
- `cd badger && go install`

This should install new badger binary in your $GOBIN
This should install the new badger binary in your `$GOBIN`.

4. Restore data from backup

Expand Down

0 comments on commit 4ea6b2f

Please sign in to comment.