コード例 #1
0
func (ss *StorageServer) RemoveFromList(args *sp.PutArgs, reply *sp.PutReply) error {
	ss.mu.RLock()
	bytes, present := ss.hashmap[args.Key]
	ss.mu.RUnlock()
	if !present {
		lsplog.Vlogf(3, "[StorageServer] key: %v, nonexist\n", args.Key)
		reply.Status = sp.EKEYNOTFOUND
		return nil
	}

	ss.revokeLease(args.Key)

	var l []string
	json.Unmarshal(bytes, &l)
	for i, v := range l {
		if v == args.Value {
			l = append(l[:i], l[i+1:]...)
			reply.Status = sp.OK
			ss.mu.Lock()
			ss.hashmap[args.Key], _ = json.Marshal(l)
			ss.mu.Unlock()
			return nil
		}
	}

	reply.Status = sp.EITEMNOTFOUND
	return nil
}
コード例 #2
0
func (ss *StorageServer) AppendToList(args *sp.PutArgs, reply *sp.PutReply) error {
	ss.revokeLease(args.Key)

	ss.mu.RLock()
	bytes, _ := ss.hashmap[args.Key]
	ss.mu.RUnlock()

	var l []string
	json.Unmarshal(bytes, &l)

	for _, v := range l {
		if v == args.Value {
			reply.Status = sp.EITEMEXISTS
			return nil
		}
	}

	l = append(l, args.Value)
	ss.mu.Lock()
	ss.hashmap[args.Key], _ = json.Marshal(l)
	ss.mu.Unlock()

	reply.Status = sp.OK
	return nil
}
コード例 #3
0
func (pc *ProxyCounter) RemoveFromList(args *storageproto.PutArgs, reply *storageproto.PutReply) error {
	if pc.override {
		reply.Status = pc.overrideStatus
		return pc.overrideErr
	}
	byteCount := len(args.Key) + len(args.Value)
	err := pc.srv.Call("StorageRPC.RemoveFromList", args, reply)
	atomic.AddUint32(&pc.rpcCount, 1)
	atomic.AddUint32(&pc.byteCount, uint32(byteCount))
	return err
}
コード例 #4
0
func (ss *StorageServer) Put(args *sp.PutArgs, reply *sp.PutReply) error {
	ss.revokeLease(args.Key)

	ss.mu.Lock()
	defer ss.mu.Unlock()

	ss.hashmap[args.Key], _ = json.Marshal(args.Value)
	reply.Status = sp.OK

	lsplog.Vlogf(3, "[StorageServer] Put, key=%v, value=%v\n", args.Key, args.Value)
	return nil
}