-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
boltdb_table_client.go
61 lines (50 loc) · 1.4 KB
/
boltdb_table_client.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
61
package local
import (
"context"
"os"
"path/filepath"
"github.com/grafana/loki/pkg/storage/config"
"github.com/grafana/loki/pkg/storage/stores/series/index"
)
type TableClient struct {
directory string
}
// NewTableClient returns a new TableClient.
func NewTableClient(directory string) (index.TableClient, error) {
return &TableClient{directory: directory}, nil
}
func (c *TableClient) ListTables(_ context.Context) ([]string, error) {
boltDbFiles := []string{}
err := filepath.Walk(c.directory, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
boltDbFiles = append(boltDbFiles, info.Name())
}
return nil
})
if err != nil {
return nil, err
}
return boltDbFiles, nil
}
func (c *TableClient) CreateTable(_ context.Context, desc config.TableDesc) error {
file, err := os.OpenFile(filepath.Join(c.directory, desc.Name), os.O_CREATE|os.O_RDONLY, 0o666)
if err != nil {
return err
}
return file.Close()
}
func (c *TableClient) DeleteTable(_ context.Context, name string) error {
return os.Remove(filepath.Join(c.directory, name))
}
func (c *TableClient) DescribeTable(_ context.Context, name string) (desc config.TableDesc, isActive bool, err error) {
return config.TableDesc{
Name: name,
}, true, nil
}
func (c *TableClient) UpdateTable(_ context.Context, _, _ config.TableDesc) error {
return nil
}
func (*TableClient) Stop() {}