This file is indexed.

/usr/share/gocode/src/github.com/lunny/nodb/multi.go is in golang-github-lunny-nodb-dev 0.0~git20160621.0.fc1ef06-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package nodb

import (
	"errors"
	"fmt"
)

var (
	ErrNestMulti = errors.New("nest multi not supported")
	ErrMultiDone = errors.New("multi has been closed")
)

type Multi struct {
	*DB
}

func (db *DB) IsInMulti() bool {
	return db.status == DBInMulti
}

// begin a mutli to execute commands,
// it will block any other write operations before you close the multi, unlike transaction, mutli can not rollback
func (db *DB) Multi() (*Multi, error) {
	if db.IsInMulti() {
		return nil, ErrNestMulti
	}

	m := new(Multi)

	m.DB = new(DB)
	m.DB.status = DBInMulti

	m.DB.l = db.l

	m.l.wLock.Lock()

	m.DB.sdb = db.sdb

	m.DB.bucket = db.sdb

	m.DB.index = db.index

	m.DB.kvBatch = m.newBatch()
	m.DB.listBatch = m.newBatch()
	m.DB.hashBatch = m.newBatch()
	m.DB.zsetBatch = m.newBatch()
	m.DB.binBatch = m.newBatch()
	m.DB.setBatch = m.newBatch()

	return m, nil
}

func (m *Multi) newBatch() *batch {
	return m.l.newBatch(m.bucket.NewWriteBatch(), &multiBatchLocker{}, nil)
}

func (m *Multi) Close() error {
	if m.bucket == nil {
		return ErrMultiDone
	}
	m.l.wLock.Unlock()
	m.bucket = nil
	return nil
}

func (m *Multi) Select(index int) error {
	if index < 0 || index >= int(MaxDBNumber) {
		return fmt.Errorf("invalid db index %d", index)
	}

	m.DB.index = uint8(index)
	return nil
}