-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathpersistent_store.go
60 lines (50 loc) · 1.86 KB
/
persistent_store.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2024 The Cockroach Authors.
//
// Use of this software is governed by the CockroachDB Software License
// included in the /LICENSE file.
package vecstore
import (
"context"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/sql/vecindex/quantize"
)
type PersistentStore struct {
db *kv.DB // Needed for index maintenance functions
quantizer quantize.Quantizer
rootQuantizer quantize.Quantizer
prefix roachpb.Key
}
var _ Store = (*PersistentStore)(nil)
func NewPersistentStore(
db *kv.DB,
quantizer quantize.Quantizer,
prefix roachpb.Key,
) *PersistentStore {
ps := PersistentStore{
db: db,
quantizer: quantizer,
rootQuantizer: quantize.NewUnQuantizer(quantizer.GetOriginalDims()),
prefix: prefix,
}
return &ps
}
// Begin() is part of the vecstore.Store interface. Begin() creates a new KV
// transaction on behalf of the user and prepares it to operate on the persistent
// vector store.
func (s *PersistentStore) Begin(ctx context.Context) (Txn, error) {
return NewPersistentStoreTxn(s, s.db.NewTxn(ctx, "vecstore.PersistentStore begin transaction")), nil
}
// Commit() is part of the vecstore.Store interface. Commit() commits the
// underlying KV transaction wrapped by the vecstore.Txn passed in.
func (s *PersistentStore) Commit(ctx context.Context, txn Txn) error {
return txn.(*PersistentStoreTxn).kv.Commit(ctx)
}
// Abort() is part of the vecstore.Store interface. Abort() causes the underlying
// KV transaction wrapped by the passed vecstore.Txn to roll back.
func (s *PersistentStore) Abort(ctx context.Context, txn Txn) error {
return txn.(*PersistentStoreTxn).kv.Rollback(ctx)
}
func (s *PersistentStore) MergeStats(ctx context.Context, stats *IndexStats, skipMerge bool) error {
panic("MergeStats() unimplemented")
}