forked from grafana/loki
/
boltdb_table_client.go
60 lines (49 loc) · 1.36 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
package local
import (
"context"
"os"
"path/filepath"
"github.com/frelon/loki/v2/pkg/storage/chunk"
)
type TableClient struct {
directory string
}
// NewTableClient returns a new TableClient.
func NewTableClient(directory string) (chunk.TableClient, error) {
return &TableClient{directory: directory}, nil
}
func (c *TableClient) ListTables(ctx 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(ctx context.Context, desc chunk.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(ctx context.Context, name string) error {
return os.Remove(filepath.Join(c.directory, name))
}
func (c *TableClient) DescribeTable(ctx context.Context, name string) (desc chunk.TableDesc, isActive bool, err error) {
return chunk.TableDesc{
Name: name,
}, true, nil
}
func (c *TableClient) UpdateTable(ctx context.Context, current, expected chunk.TableDesc) error {
return nil
}
func (*TableClient) Stop() {}