Skip to content
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Commit

Permalink
Remove leveldb read write locks as leveldb already threadsafe. (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadlil authored and tamalsaha committed Jan 26, 2017
1 parent 0cdca0e commit 91753d2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package client

import (
"testing"
"time"

rt "github.com/appscode/g2/pkg/runtime"
"github.com/appscode/log"
"time"
)

const (
Expand Down
7 changes: 4 additions & 3 deletions cmd/gearmand/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
package main

import (
"os"

gearmand "github.com/appscode/g2/pkg/server"
"github.com/appscode/g2/pkg/storage"
"github.com/appscode/g2/pkg/storage/leveldb"
Expand All @@ -10,12 +12,11 @@ import (
"github.com/appscode/log"
logs "github.com/appscode/log/golog"
"github.com/spf13/pflag"
"os"
)

var (
addr string
storageDir string
addr string
storageDir string
)

func main() {
Expand Down
22 changes: 1 addition & 21 deletions pkg/storage/leveldb/leveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"reflect"
"strings"
"sync"

. "github.com/appscode/g2/pkg/runtime"
"github.com/appscode/g2/pkg/storage"
Expand All @@ -16,7 +15,6 @@ import (
)

type LevelDbQ struct {
l sync.RWMutex
db *leveldb.DB
}

Expand All @@ -27,7 +25,7 @@ func New(dir string) (storage.Db, error) {
if err != nil {
return nil, err
}
return &LevelDbQ{db: db, l: sync.RWMutex{}}, nil
return &LevelDbQ{db: db}, nil
}

func (q *LevelDbQ) AddJob(j *Job) error {
Expand All @@ -43,9 +41,6 @@ func (q *LevelDbQ) AddJob(j *Job) error {
if err != nil {
return err
}

q.l.Lock()
defer q.l.Unlock()
return q.db.Put([]byte(j.Handle), buf, nil)
}

Expand All @@ -62,16 +57,11 @@ func (q *LevelDbQ) DeleteJob(j *Job, isSuccess bool) error {
}
q.AddCronJob(cj)
}
q.l.Lock()
defer q.l.Unlock()
return q.db.Delete([]byte(j.Handle), nil)
}

func (q *LevelDbQ) GetJob(handle string) (*Job, error) {
q.l.RLock()
data, err := q.db.Get([]byte(handle), nil)
q.l.RUnlock()

if err != nil {
return nil, err
}
Expand All @@ -84,8 +74,6 @@ func (q *LevelDbQ) GetJob(handle string) (*Job, error) {
}

func (q *LevelDbQ) GetJobs() ([]*Job, error) {
q.l.RLock()
defer q.l.RUnlock()
jobs := make([]*Job, 0)
iter := q.db.NewIterator(util.BytesPrefix([]byte(JobPrefix)), nil)
for iter.Next() {
Expand All @@ -111,8 +99,6 @@ func (q *LevelDbQ) AddCronJob(sj *CronJob) error {
if err != nil {
return err
}
q.l.Lock()
defer q.l.Unlock()
return q.db.Put([]byte(sj.Handle), buf, nil)
}

Expand All @@ -133,9 +119,7 @@ func (q *LevelDbQ) UpdateCronJob(handle string, updatedValue map[string]interfac
}

func (q *LevelDbQ) GetCronJob(handle string) (*CronJob, error) {
q.l.RLock()
data, err := q.db.Get([]byte(handle), nil)
q.l.RUnlock()

if err != nil {
return nil, err
Expand All @@ -153,15 +137,11 @@ func (q *LevelDbQ) DeleteCronJob(sj *CronJob) (*CronJob, error) {
if err != nil {
return nil, err
}
q.l.Lock()
defer q.l.Unlock()
return cj, q.db.Delete([]byte(cj.Handle), nil)
}

func (q *LevelDbQ) GetCronJobs() ([]*CronJob, error) {
cronJobs := make([]*CronJob, 0)
q.l.RLock()
defer q.l.RUnlock()
iter := q.db.NewIterator(util.BytesPrefix([]byte(SchedJobPrefix)), nil)
for iter.Next() {
// key := iter.Key()
Expand Down

0 comments on commit 91753d2

Please sign in to comment.