Commit 70540a69 authored by Steven Allen's avatar Steven Allen

chore: fix lint errors

parent 6e6008d2
...@@ -490,7 +490,7 @@ func (fs *Datastore) putMany(data map[datastore.Key][]byte) error { ...@@ -490,7 +490,7 @@ func (fs *Datastore) putMany(data map[datastore.Key][]byte) error {
defer func() { defer func() {
for fi := range files { for fi := range files {
val, _ := ops[fi] val := ops[fi]
switch val { switch val {
case 0: case 0:
_ = fi.Close() _ = fi.Close()
...@@ -667,7 +667,7 @@ func (fs *Datastore) Query(q query.Query) (query.Results, error) { ...@@ -667,7 +667,7 @@ func (fs *Datastore) Query(q query.Query) (query.Results, error) {
case <-p.Closing(): case <-p.Closing():
} }
}) })
go b.Process.CloseAfterChildren() go b.Process.CloseAfterChildren() //nolint
return b.Results(), nil return b.Results(), nil
} }
...@@ -1045,20 +1045,20 @@ func (fs *Datastore) walk(path string, result *query.ResultBuilder) error { ...@@ -1045,20 +1045,20 @@ func (fs *Datastore) walk(path string, result *query.ResultBuilder) error {
// Deactivate closes background maintenance threads, most write // Deactivate closes background maintenance threads, most write
// operations will fail but readonly operations will continue to // operations will fail but readonly operations will continue to
// function // function
func (fs *Datastore) deactivate() error { func (fs *Datastore) deactivate() {
fs.shutdownLock.Lock() fs.shutdownLock.Lock()
defer fs.shutdownLock.Unlock() defer fs.shutdownLock.Unlock()
if fs.shutdown { if fs.shutdown {
return nil return
} }
fs.shutdown = true fs.shutdown = true
close(fs.checkpointCh) close(fs.checkpointCh)
<-fs.done <-fs.done
return nil
} }
func (fs *Datastore) Close() error { func (fs *Datastore) Close() error {
return fs.deactivate() fs.deactivate()
return nil
} }
type flatfsBatch struct { type flatfsBatch struct {
...@@ -1091,7 +1091,7 @@ func (bt *flatfsBatch) Commit() error { ...@@ -1091,7 +1091,7 @@ func (bt *flatfsBatch) Commit() error {
return err return err
} }
for k, _ := range bt.deletes { for k := range bt.deletes {
if err := bt.ds.Delete(k); err != nil { if err := bt.ds.Delete(k); err != nil {
return err return err
} }
......
...@@ -561,7 +561,7 @@ func testDiskUsageDoubleCount(dirFunc mkShardFunc, t *testing.T) { ...@@ -561,7 +561,7 @@ func testDiskUsageDoubleCount(dirFunc mkShardFunc, t *testing.T) {
v := []byte("10bytes---") v := []byte("10bytes---")
err := fs.Put(testKey, v) err := fs.Put(testKey, v)
if err != nil { if err != nil {
t.Fatalf("Put fail: %v\n", err) t.Errorf("Put fail: %v\n", err)
} }
} }
} }
...@@ -571,7 +571,7 @@ func testDiskUsageDoubleCount(dirFunc mkShardFunc, t *testing.T) { ...@@ -571,7 +571,7 @@ func testDiskUsageDoubleCount(dirFunc mkShardFunc, t *testing.T) {
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
err := fs.Delete(testKey) err := fs.Delete(testKey)
if err != nil && !strings.Contains(err.Error(), "key not found") { if err != nil && !strings.Contains(err.Error(), "key not found") {
t.Fatalf("Delete fail: %v\n", err) t.Errorf("Delete fail: %v\n", err)
} }
} }
} }
...@@ -624,7 +624,10 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) { ...@@ -624,7 +624,10 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
} }
defer fs.Close() defer fs.Close()
fsBatch, _ := fs.Batch() fsBatch, err := fs.Batch()
if err != nil {
t.Fatal(err)
}
count := 200 count := 200
var wg sync.WaitGroup var wg sync.WaitGroup
...@@ -636,14 +639,17 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) { ...@@ -636,14 +639,17 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
put := func() { put := func() {
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
fsBatch.Put(testKeys[i], []byte("10bytes---")) err := fsBatch.Put(testKeys[i], []byte("10bytes---"))
if err != nil {
t.Error(err)
}
} }
} }
commit := func() { commit := func() {
defer wg.Done() defer wg.Done()
err := fsBatch.Commit() err := fsBatch.Commit()
if err != nil { if err != nil {
t.Fatalf("Batch Put fail: %v\n", err) t.Errorf("Batch Put fail: %v\n", err)
} }
} }
...@@ -652,7 +658,7 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) { ...@@ -652,7 +658,7 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
for _, k := range testKeys { for _, k := range testKeys {
err := fs.Delete(k) err := fs.Delete(k)
if err != nil && !strings.Contains(err.Error(), "key not found") { if err != nil && !strings.Contains(err.Error(), "key not found") {
t.Fatalf("Delete fail: %v\n", err) t.Errorf("Delete fail: %v\n", err)
} }
} }
} }
...@@ -662,9 +668,15 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) { ...@@ -662,9 +668,15 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
wg.Add(2) wg.Add(2)
put() put()
commit() commit()
du, _ := fs.DiskUsage() du, err := fs.DiskUsage()
if err != nil {
t.Fatal(err)
}
del() del()
du2, _ := fs.DiskUsage() du2, err := fs.DiskUsage()
if err != nil {
t.Fatal(err)
}
if du-uint64(10*count) != du2 { if du-uint64(10*count) != du2 {
t.Errorf("should have deleted exactly %d bytes: %d %d", 10*count, du, du2) t.Errorf("should have deleted exactly %d bytes: %d %d", 10*count, du, du2)
} }
...@@ -676,11 +688,17 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) { ...@@ -676,11 +688,17 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
go del() go del()
wg.Wait() wg.Wait()
du3, _ := fs.DiskUsage() du3, err := fs.DiskUsage()
if err != nil {
t.Fatal(err)
}
// Now query how many keys we have // Now query how many keys we have
results, err := fs.Query(query.Query{ results, err := fs.Query(query.Query{
KeysOnly: true, KeysOnly: true,
}) })
if err != nil {
t.Fatal(err)
}
rest, err := results.Rest() rest, err := results.Rest()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -862,6 +880,7 @@ func TestSHARDINGFile(t *testing.T) { ...@@ -862,6 +880,7 @@ func TestSHARDINGFile(t *testing.T) {
fs, err = flatfs.CreateOrOpen(tempdir, flatfs.Prefix(5), false) fs, err = flatfs.CreateOrOpen(tempdir, flatfs.Prefix(5), false)
if err == nil { if err == nil {
fs.Close()
t.Fatalf("Was able to open repo with incompatible sharding function") t.Fatalf("Was able to open repo with incompatible sharding function")
} }
} }
...@@ -877,9 +896,12 @@ func TestNonDatastoreDir(t *testing.T) { ...@@ -877,9 +896,12 @@ func TestNonDatastoreDir(t *testing.T) {
tempdir, cleanup := tempdir(t) tempdir, cleanup := tempdir(t)
defer cleanup() defer cleanup()
ioutil.WriteFile(filepath.Join(tempdir, "afile"), []byte("Some Content"), 0644) err := ioutil.WriteFile(filepath.Join(tempdir, "afile"), []byte("Some Content"), 0644)
if err != nil {
t.Fatal(err)
}
err := flatfs.Create(tempdir, flatfs.NextToLast(2)) err = flatfs.Create(tempdir, flatfs.NextToLast(2))
if err == nil { if err == nil {
t.Fatalf("Expected an error when creating a datastore in a non-empty directory") t.Fatalf("Expected an error when creating a datastore in a non-empty directory")
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment