Developing lightweight computation at the DSG edge

Commit 2cf114f9 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[goclidote] Add function to add an item to a set in a map in a bucket



The function is called, yes, AntidoteAddItemToSetInMapInBucket().
Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent 206b9c54
......@@ -65,7 +65,39 @@ func AntidoteAddItemToSetInBucket(bucketName string, setName string, itemValue s
// AntidoteAddItemToSetInMapInBucket save an item to a set in a map in a bucket
func AntidoteAddItemToSetInMapInBucket(bucketName string, mapName string, setName string, itemValue string, DatabaseHost string, DatabasePort int) bool {
return true
client, err := antidoteclient.NewClient(antidoteclient.Host{Name: DatabaseHost, Port: DatabasePort})
errCheck(err, ERROR, "[AntidoteAddItemToSetInMapInBucket]: Unable to create a new AntidoteDB go client")
defer client.Close()
//TODO: remove this line
// fmt.Printf("About to write data \"%s\" in set \"%s\" in map \"%s\" in bucket \"%s\"", itemValue, setName, mapName, bucketName)
tx, err := client.StartTransaction()
errCheck(err, ERROR, "[AntidoteAddItemToSetInMapInBucket]: Unable to start a transaction using the go client")
bucket := antidoteclient.Bucket{Bucket: []byte(bucketName)}
mapKey := antidoteclient.Key(mapName)
setKey := antidoteclient.Key(setName)
err = bucket.Update(tx, antidoteclient.MapUpdate(mapKey,
antidoteclient.SetAdd(setKey, []byte(itemValue))))
errCheck(err, ERROR, fmt.Sprintf("[AntidoteAddItemToSetInMapInBucket]: Unable to add value %s to set %s in bucket %s", itemValue, setName, bucketName))
mapVal, err := bucket.ReadMap(tx, mapKey)
errCheck(err, ERROR, fmt.Sprintf("[AntidoteAddItemToSetInMapInBucket]: Unable to read set %s in bucket %s", setName, bucketName))
setVal, err := mapVal.Set(setKey)
errCheck(err, ERROR, fmt.Sprintf("[AntidoteAddItemToSetInMapInBucket]: Unable to read set %s in bucket %s", setName, bucketName))
// Return true if the value belongs now to the set (either it has been added now, or was there already)
for _, v := range setVal {
if string(v) == itemValue {
return true
}
}
// Return false otherwise
return false
}
// AntidoteReadRegisterInBucket read a LWWW register in a bucket
......
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