aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/go.etcd.io/bbolt/db.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-06-10 16:44:25 +0200
committerGitHub <noreply@github.com>2021-06-10 16:44:25 +0200
commit86e2789960439ca786c6e7a74f85f076c223d148 (patch)
treec63064d4258bcf2bb7a2e5e60acc0a5d5c8216da /vendor/go.etcd.io/bbolt/db.go
parentf088dc4ea14ae6304c2e06fca06ffa2f7bc273f3 (diff)
downloadgitea-86e2789960439ca786c6e7a74f85f076c223d148.tar.gz
gitea-86e2789960439ca786c6e7a74f85f076c223d148.zip
Vendor Update (#16121)
* update github.com/PuerkitoBio/goquery * update github.com/alecthomas/chroma * update github.com/blevesearch/bleve/v2 * update github.com/caddyserver/certmagic * update github.com/go-enry/go-enry/v2 * update github.com/go-git/go-billy/v5 * update github.com/go-git/go-git/v5 * update github.com/go-redis/redis/v8 * update github.com/go-testfixtures/testfixtures/v3 * update github.com/jaytaylor/html2text * update github.com/json-iterator/go * update github.com/klauspost/compress * update github.com/markbates/goth * update github.com/mattn/go-isatty * update github.com/mholt/archiver/v3 * update github.com/microcosm-cc/bluemonday * update github.com/minio/minio-go/v7 * update github.com/prometheus/client_golang * update github.com/unrolled/render * update github.com/xanzy/go-gitlab * update github.com/yuin/goldmark * update github.com/yuin/goldmark-highlighting Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'vendor/go.etcd.io/bbolt/db.go')
-rw-r--r--vendor/go.etcd.io/bbolt/db.go66
1 files changed, 62 insertions, 4 deletions
diff --git a/vendor/go.etcd.io/bbolt/db.go b/vendor/go.etcd.io/bbolt/db.go
index 80b0095cc3..a798c390a2 100644
--- a/vendor/go.etcd.io/bbolt/db.go
+++ b/vendor/go.etcd.io/bbolt/db.go
@@ -120,6 +120,12 @@ type DB struct {
// of truncate() and fsync() when growing the data file.
AllocSize int
+ // Mlock locks database file in memory when set to true.
+ // It prevents major page faults, however used memory can't be reclaimed.
+ //
+ // Supported only on Unix via mlock/munlock syscalls.
+ Mlock bool
+
path string
openFile func(string, int, os.FileMode) (*os.File, error)
file *os.File
@@ -188,6 +194,7 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
db.MmapFlags = options.MmapFlags
db.NoFreelistSync = options.NoFreelistSync
db.FreelistType = options.FreelistType
+ db.Mlock = options.Mlock
// Set default values for later DB operations.
db.MaxBatchSize = DefaultMaxBatchSize
@@ -337,7 +344,8 @@ func (db *DB) mmap(minsz int) error {
}
// Ensure the size is at least the minimum size.
- var size = int(info.Size())
+ fileSize := int(info.Size())
+ var size = fileSize
if size < minsz {
size = minsz
}
@@ -346,6 +354,13 @@ func (db *DB) mmap(minsz int) error {
return err
}
+ if db.Mlock {
+ // Unlock db memory
+ if err := db.munlock(fileSize); err != nil {
+ return err
+ }
+ }
+
// Dereference all mmap references before unmapping.
if db.rwtx != nil {
db.rwtx.root.dereference()
@@ -361,6 +376,13 @@ func (db *DB) mmap(minsz int) error {
return err
}
+ if db.Mlock {
+ // Don't allow swapping of data file
+ if err := db.mlock(fileSize); err != nil {
+ return err
+ }
+ }
+
// Save references to the meta pages.
db.meta0 = db.page(0).meta()
db.meta1 = db.page(1).meta()
@@ -422,12 +444,36 @@ func (db *DB) mmapSize(size int) (int, error) {
return int(sz), nil
}
+func (db *DB) munlock(fileSize int) error {
+ if err := munlock(db, fileSize); err != nil {
+ return fmt.Errorf("munlock error: " + err.Error())
+ }
+ return nil
+}
+
+func (db *DB) mlock(fileSize int) error {
+ if err := mlock(db, fileSize); err != nil {
+ return fmt.Errorf("mlock error: " + err.Error())
+ }
+ return nil
+}
+
+func (db *DB) mrelock(fileSizeFrom, fileSizeTo int) error {
+ if err := db.munlock(fileSizeFrom); err != nil {
+ return err
+ }
+ if err := db.mlock(fileSizeTo); err != nil {
+ return err
+ }
+ return nil
+}
+
// init creates a new database file and initializes its meta pages.
func (db *DB) init() error {
// Create two meta pages on a buffer.
buf := make([]byte, db.pageSize*4)
for i := 0; i < 2; i++ {
- p := db.pageInBuffer(buf[:], pgid(i))
+ p := db.pageInBuffer(buf, pgid(i))
p.id = pgid(i)
p.flags = metaPageFlag
@@ -444,13 +490,13 @@ func (db *DB) init() error {
}
// Write an empty freelist at page 3.
- p := db.pageInBuffer(buf[:], pgid(2))
+ p := db.pageInBuffer(buf, pgid(2))
p.id = pgid(2)
p.flags = freelistPageFlag
p.count = 0
// Write an empty leaf page at page 4.
- p = db.pageInBuffer(buf[:], pgid(3))
+ p = db.pageInBuffer(buf, pgid(3))
p.id = pgid(3)
p.flags = leafPageFlag
p.count = 0
@@ -462,6 +508,7 @@ func (db *DB) init() error {
if err := fdatasync(db); err != nil {
return err
}
+ db.filesz = len(buf)
return nil
}
@@ -973,6 +1020,12 @@ func (db *DB) grow(sz int) error {
if err := db.file.Sync(); err != nil {
return fmt.Errorf("file sync error: %s", err)
}
+ if db.Mlock {
+ // unlock old file and lock new one
+ if err := db.mrelock(db.filesz, sz); err != nil {
+ return fmt.Errorf("mlock/munlock error: %s", err)
+ }
+ }
}
db.filesz = sz
@@ -1064,6 +1117,11 @@ type Options struct {
// OpenFile is used to open files. It defaults to os.OpenFile. This option
// is useful for writing hermetic tests.
OpenFile func(string, int, os.FileMode) (*os.File, error)
+
+ // Mlock locks database file in memory when set to true.
+ // It prevents potential page faults, however
+ // used memory can't be reclaimed. (UNIX only)
+ Mlock bool
}
// DefaultOptions represent the options used if nil options are passed into Open().