can now delete a collection! Is this a dangerous feature? Only enabling

deleting "benchmark" collections for now.
This commit is contained in:
Chris Lu
2014-03-10 11:43:54 -07:00
parent a121453188
commit cd10c277b2
13 changed files with 130 additions and 8 deletions

View File

@@ -64,6 +64,10 @@ func (m *cdbMap) Close() {
}
}
func (m *cdbMap) Destroy() error {
return errors.New("Can not delete readonly volumes")
}
func (m cdbMap) ContentSize() uint64 {
return m.FileByteCounter
}

View File

@@ -14,6 +14,7 @@ type NeedleMapper interface {
Get(key uint64) (element *NeedleValue, ok bool)
Delete(key uint64) error
Close()
Destroy() error
ContentSize() uint64
DeletedSize() uint64
FileCount() int
@@ -155,6 +156,10 @@ func (nm *NeedleMap) Delete(key uint64) error {
func (nm *NeedleMap) Close() {
_ = nm.indexFile.Close()
}
func (nm *NeedleMap) Destroy() error {
nm.Close()
return os.Remove(nm.indexFile.Name())
}
func (nm NeedleMap) ContentSize() uint64 {
return nm.FileByteCounter
}

View File

@@ -111,6 +111,20 @@ func (s *Store) AddVolume(volumeListString string, collection string, replicaPla
}
return e
}
func (s *Store) DeleteCollection(collection string) (e error) {
for _, location := range s.locations {
for k, v := range location.volumes {
if v.Collection == collection {
e = v.Destroy()
if e != nil {
return
}
delete(location.volumes, k)
}
}
}
return
}
func (s *Store) findVolume(vid VolumeId) *Volume {
for _, location := range s.locations {
if v, found := location.volumes[vid]; found {

View File

@@ -197,6 +197,21 @@ func (v *Volume) isFileUnchanged(n *Needle) bool {
}
return false
}
func (v *Volume) Destroy() (err error) {
if v.readOnly {
err = fmt.Errorf("%s is read-only", v.dataFile)
return
}
v.Close()
err = os.Remove(v.dataFile.Name())
if err != nil {
return
}
err = v.nm.Destroy()
return
}
func (v *Volume) write(n *Needle) (size uint32, err error) {
if v.readOnly {
err = fmt.Errorf("%s is read-only", v.dataFile)