コード例 #1
0
func (self *ReplicaClient) ListAppend(kv *trib.KeyValue, succ *bool) error {
	var clk uint64
	*succ = true
	err1 := self.Clock(0, &clk)
	if err1 != nil {
		return err1
	}

	var newkv trib.KeyValue
	newkv.Key = colon.Escape(self.name) + "::" + kv.Key + "list"
	log := BinLog{"append", kv.Value, clk}
	newkv.Value = EncodeLog(log)

	success := false
	for _, ad := range self.addr {
		tempclient := &client{ad}
		var b bool
		err2 := tempclient.ListAppend(&newkv, &b)
		if err2 == nil {
			success = true
		}
	}

	if success == true {
		return nil
	} else {
		return fmt.Errorf("ListAppend failure on all servers")
	}

}
コード例 #2
0
ファイル: lab2.go プロジェクト: ymqytw/cse223_distSys_lab
func (self *clientWithPrefix) ListRemove(kv *trib.KeyValue, n *int) error {
	// escape colon
	binName := colon.Escape(self.bin)
	kv.Key = colon.Escape(kv.Key)
	kv.Key = binName + "::" + kv.Key

	// RPC call
	return self.originalClient.ListRemove(kv, n)
}
コード例 #3
0
ファイル: lab2.go プロジェクト: ymqytw/cse223_distSys_lab
func (self *clientWithPrefix) ListAppend(kv *trib.KeyValue, succ *bool) error {
	// escape colon
	binName := colon.Escape(self.bin)
	kv.Key = colon.Escape(kv.Key)
	kv.Key = binName + "::" + kv.Key

	// RPC call
	return self.originalClient.ListAppend(kv, succ)
}
コード例 #4
0
func (self *ReplicaClient) ListRemove(kv *trib.KeyValue, n *int) error {
	var clk uint64
	err1 := self.Clock(0, &clk)
	if err1 != nil {
		return err1
	}

	var tempList trib.List
	self.ListGet(kv.Key, &tempList)

	r := 0
	for _, element := range tempList.L {
		if element == kv.Value {
			r++
		}
	}

	*n = r

	var newkv trib.KeyValue
	newkv.Key = colon.Escape(self.name) + "::" + kv.Key + "list"
	log := BinLog{"remove", kv.Value, clk}
	newkv.Value = EncodeLog(log)

	success := false
	for _, ad := range self.addr {
		tempclient := &client{ad}
		var b bool
		err2 := tempclient.ListAppend(&newkv, &b)
		if err2 == nil {
			success = true
		}
	}

	if success == true {
		return nil
	} else {
		return fmt.Errorf("ListRemove failure on all servers")
	}
}