Commit 57b15e58 authored by Sushant Mahajan's avatar Sushant Mahajan

per key level versioning and tests modularized

parent d233a3c1
...@@ -57,12 +57,12 @@ type KeyValueStore struct { ...@@ -57,12 +57,12 @@ type KeyValueStore struct {
sync.RWMutex //mutex for synchronization when reading or writing to the hashtable sync.RWMutex //mutex for synchronization when reading or writing to the hashtable
} }
//global version counter
var ver uint64
//pointer to custom logger //pointer to custom logger
var logger *log.Logger var logger *log.Logger
//cache
var table *KeyValueStore
/*Function to start the server and accept connections. /*Function to start the server and accept connections.
*arguments: none *arguments: none
*return: none *return: none
...@@ -75,7 +75,7 @@ func startServer() { ...@@ -75,7 +75,7 @@ func startServer() {
} }
//initialize key value store //initialize key value store
table := &KeyValueStore{dictionary: make(map[string]*Data)} table = &KeyValueStore{dictionary: make(map[string]*Data)}
//infinite loop //infinite loop
for { for {
...@@ -458,9 +458,8 @@ func performSet(conn net.Conn, tokens []string, table *KeyValueStore, ch chan [] ...@@ -458,9 +458,8 @@ func performSet(conn net.Conn, tokens []string, table *KeyValueStore, ch chan []
val = new(Data) val = new(Data)
table.dictionary[k] = val table.dictionary[k] = val
} }
ver++
val.numBytes = n val.numBytes = n
val.version = ver val.version++
if e == 0 { if e == 0 {
val.isPerpetual = true val.isPerpetual = true
val.expTime = 0 val.expTime = 0
...@@ -561,8 +560,7 @@ func performCas(conn net.Conn, tokens []string, table *KeyValueStore, ch chan [] ...@@ -561,8 +560,7 @@ func performCas(conn net.Conn, tokens []string, table *KeyValueStore, ch chan []
val.expTime = e + uint64(time.Now().Unix()) val.expTime = e + uint64(time.Now().Unix())
} }
val.numBytes = n val.numBytes = n
ver++ val.version++
val.version = ver
val.value = v val.value = v
//key found and changed //key found and changed
return val.version, 0, r return val.version, 0, r
...@@ -654,8 +652,6 @@ func CustomSplitter(data []byte, atEOF bool) (advance int, token []byte, err err ...@@ -654,8 +652,6 @@ func CustomSplitter(data []byte, atEOF bool) (advance int, token []byte, err err
*return: none *return: none
*/ */
func main() { func main() {
ver = 1
toLog := "" toLog := ""
if len(os.Args) > 1 { if len(os.Args) > 1 {
toLog = os.Args[1] toLog = os.Args[1]
...@@ -675,3 +671,11 @@ func main() { ...@@ -675,3 +671,11 @@ func main() {
var input string var input string
fmt.Scanln(&input) fmt.Scanln(&input)
} }
//server will not call this, we'll call it from test cases to clear the map
func ReInitServer() {
for key, _ := range table.dictionary {
delete(table.dictionary, key)
}
//fmt.Println(table.dictionary)
}
This diff is collapsed.
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