github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/storage/chunk/client/local/boltdb_table_client.go (about) 1 package local 2 3 import ( 4 "context" 5 "os" 6 "path/filepath" 7 8 "github.com/grafana/loki/pkg/storage/config" 9 "github.com/grafana/loki/pkg/storage/stores/series/index" 10 ) 11 12 type TableClient struct { 13 directory string 14 } 15 16 // NewTableClient returns a new TableClient. 17 func NewTableClient(directory string) (index.TableClient, error) { 18 return &TableClient{directory: directory}, nil 19 } 20 21 func (c *TableClient) ListTables(ctx context.Context) ([]string, error) { 22 boltDbFiles := []string{} 23 err := filepath.Walk(c.directory, func(path string, info os.FileInfo, err error) error { 24 if err != nil { 25 return err 26 } 27 if !info.IsDir() { 28 boltDbFiles = append(boltDbFiles, info.Name()) 29 } 30 return nil 31 }) 32 if err != nil { 33 return nil, err 34 } 35 return boltDbFiles, nil 36 } 37 38 func (c *TableClient) CreateTable(ctx context.Context, desc config.TableDesc) error { 39 file, err := os.OpenFile(filepath.Join(c.directory, desc.Name), os.O_CREATE|os.O_RDONLY, 0o666) 40 if err != nil { 41 return err 42 } 43 44 return file.Close() 45 } 46 47 func (c *TableClient) DeleteTable(ctx context.Context, name string) error { 48 return os.Remove(filepath.Join(c.directory, name)) 49 } 50 51 func (c *TableClient) DescribeTable(ctx context.Context, name string) (desc config.TableDesc, isActive bool, err error) { 52 return config.TableDesc{ 53 Name: name, 54 }, true, nil 55 } 56 57 func (c *TableClient) UpdateTable(ctx context.Context, current, expected config.TableDesc) error { 58 return nil 59 } 60 61 func (*TableClient) Stop() {}