github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/chunk/local/boltdb_table_client.go (about) 1 package local 2 3 import ( 4 "context" 5 "os" 6 "path/filepath" 7 8 "github.com/cortexproject/cortex/pkg/chunk" 9 ) 10 11 type TableClient struct { 12 directory string 13 } 14 15 // NewTableClient returns a new TableClient. 16 func NewTableClient(directory string) (chunk.TableClient, error) { 17 return &TableClient{directory: directory}, nil 18 } 19 20 func (c *TableClient) ListTables(ctx context.Context) ([]string, error) { 21 boltDbFiles := []string{} 22 err := filepath.Walk(c.directory, func(path string, info os.FileInfo, err error) error { 23 if err != nil { 24 return err 25 } 26 if !info.IsDir() { 27 boltDbFiles = append(boltDbFiles, info.Name()) 28 } 29 return nil 30 }) 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 chunk.TableDesc) error { 39 file, err := os.OpenFile(filepath.Join(c.directory, desc.Name), os.O_CREATE|os.O_RDONLY, 0666) 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 chunk.TableDesc, isActive bool, err error) { 52 return chunk.TableDesc{ 53 Name: name, 54 }, true, nil 55 } 56 57 func (c *TableClient) UpdateTable(ctx context.Context, current, expected chunk.TableDesc) error { 58 return nil 59 } 60 61 func (*TableClient) Stop() {}