-
Notifications
You must be signed in to change notification settings - Fork 6
/
db_info.go
43 lines (36 loc) · 1.44 KB
/
db_info.go
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
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package server
// This file defines internal methods for manipulating dbInfo. None of these
// methods perform authorization checks.
//
// These methods are needed because information about a database is spread
// across two storage engines: existence of a database is tracked in the
// service-level storage engine, while permissions for a database are tracked in
// the database's storage engine.
import (
"v.io/v23/context"
wire "v.io/v23/services/syncbase"
"v.io/x/ref/services/syncbase/common"
"v.io/x/ref/services/syncbase/store"
)
func dbInfoStKey(dbId wire.Id) string {
return common.JoinKeyParts(common.DbInfoPrefix, common.EncodeIdKeyPart(dbId))
}
// getDbInfo reads data from the storage engine.
func getDbInfo(ctx *context.T, sntx store.SnapshotOrTransaction, dbId wire.Id) (*DbInfo, error) {
info := &DbInfo{}
if err := store.Get(ctx, sntx, dbInfoStKey(dbId), info); err != nil {
return nil, err
}
return info, nil
}
// putDbInfo writes data to the storage engine.
func putDbInfo(ctx *context.T, tx store.Transaction, info *DbInfo) error {
return store.Put(ctx, tx, dbInfoStKey(info.Id), info)
}
// delDbInfo deletes data from the storage engine.
func delDbInfo(ctx *context.T, stw store.StoreWriter, dbId wire.Id) error {
return store.Delete(ctx, stw, dbInfoStKey(dbId))
}