Skip to content

Commit

Permalink
fix import cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
sjcsjc123 committed Aug 20, 2023
1 parent ee2a46b commit 2b8a095
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions db/column/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func NewColumn(option config.ColumnOptions) (Column, error) {
option.DbMemoryOptions.ColumnName = "default"
}

// set wal, the wal is a global wal of all column family
option.DbMemoryOptions.Wal = w

// create a new db
Expand Down Expand Up @@ -93,6 +94,7 @@ func (c *column) CreateColumnFamily(name string) error {
if _, ok := c.columnFamily[name]; ok {
return errors.New("column family already exists")
}
c.option.DbMemoryOptions.ColumnName = name
db, err := memory.NewDB(c.option.DbMemoryOptions)
if err != nil {
return err
Expand All @@ -107,6 +109,10 @@ func (c *column) DropColumnFamily(name string) error {
if _, ok := c.columnFamily[name]; !ok {
return errors.New("column family not exists")
}
err := os.RemoveAll(c.option.DbMemoryOptions.Option.DirPath + "/" + name)
if err != nil {
return err
}
delete(c.columnFamily, name)
return nil
}
Expand Down
5 changes: 5 additions & 0 deletions db/memory/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ type Db struct {
errMsgCh chan []byte
}

// NewDB create a new db of wal and memTable
func NewDB(option config.DbMemoryOptions) (*Db, error) {
// create a new memTable
mem := NewMemTable()
// dir path has been changed to dir path + column name
option.Option.DirPath = option.Option.DirPath + "/" + option.ColumnName
db, err := engine.NewDB(option.Option)
if err != nil {
return nil, err
}
w := option.Wal
// if wal is nil, create a new wal
// if wal is not nil, the wal was created by column family
if option.Wal == nil {
walOptions := wal.Options{
DirPath: option.Option.DirPath,
Expand Down

0 comments on commit 2b8a095

Please sign in to comment.