当前位置: 首页>>代码示例>>Golang>>正文


Golang storageproto.PutReply类代码示例

本文整理汇总了Golang中P2-f12/official/storageproto.PutReply的典型用法代码示例。如果您正苦于以下问题:Golang PutReply类的具体用法?Golang PutReply怎么用?Golang PutReply使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PutReply类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: RemoveFromList

func (ss *Storageserver) RemoveFromList(args *storageproto.PutArgs, reply *storageproto.PutReply) error {
	if !ss.CheckWithinRange(args.Key) {
		reply.Status = storageproto.EWRONGSERVER
		return nil
	}
	ss.modifyingListLock.Lock()
	ss.modifyingList[args.Key] = new(bool)
	ss.modifyingListLock.Unlock()
	ss.revokeLeasesList(args.Key)
	ss.storageListLock.Lock()
	lst := ss.storageList[args.Key]
	var rem *list.Element
	for e := lst.Front(); e != nil; e = e.Next() {
		if e.Value == args.Value {
			rem = e
		}
	}
	if rem == nil {
		reply.Status = storageproto.EITEMNOTFOUND
		ss.storageListLock.Unlock()
		return nil
	}
	lst.Remove(rem)
	ss.storageListLock.Unlock()
	ss.modifyingListLock.Lock()
	delete(ss.modifyingList, args.Key)
	ss.modifyingListLock.Unlock()
	reply.Status = storageproto.OK
	return nil
}
开发者ID:ammarar,项目名称:DS-P2,代码行数:30,代码来源:storageimpl.go

示例2: Put

func (ss *Storageserver) Put(args *storageproto.PutArgs, reply *storageproto.PutReply) error {
	//fmt.Println("called put")
	//fmt.Printf("key: %v\n", args.Key)

	rightServer := ss.checkServer(args.Key)

	if rightServer == false {
		//fmt.Println("wrong server Put")
		reply.Status = storageproto.EWRONGSERVER
		return nil
	}

	//if we are changing something that people have leases on we have to invalidate all leases
	<-ss.leaseMapM
	_, exists := ss.leaseMap[args.Key]
	ss.leaseMapM <- 1

	if exists == true {
		ss.revokeLeases(args.Key)
	}

	<-ss.valMapM
	ss.valMap[args.Key] = args.Value
	ss.valMapM <- 1

	reply.Status = storageproto.OK

	//fmt.Printf("Put value %v for key %v\n", args.Value, args.Key)

	return nil
}
开发者ID:karomancer,项目名称:Tribbler,代码行数:31,代码来源:storageimpl.go

示例3: RemoveFromList

func (ss *Storageserver) RemoveFromList(args *storageproto.PutArgs, reply *storageproto.PutReply) error {

	//fmt.Println("called remove from List")
	//fmt.Printf("key: %v\n", args.Key)

	rightServer := ss.checkServer(args.Key)

	if rightServer == false {
		reply.Status = storageproto.EWRONGSERVER
		return nil
	}

	//if we are changing something that people have leases on we have to invalidate all leases
	<-ss.leaseMapM
	_, exists := ss.leaseMap[args.Key]
	ss.leaseMapM <- 1

	if exists == true {
		ss.revokeLeases(args.Key)
	}

	<-ss.listMapM
	list, ok := ss.listMap[args.Key]
	ss.listMapM <- 1

	if ok == false {
		reply.Status = storageproto.EKEYNOTFOUND
		return nil
	}

	j := -1
	newlist := []string{}
	for i := 0; i < len(list); i++ {
		if list[i] == args.Value {
			j = i
		} else {
			newlist = append(newlist, list[i])
		}
	}

	if j == -1 {
		reply.Status = storageproto.EITEMNOTFOUND
		return nil
	}

	<-ss.listMapM
	ss.listMap[args.Key] = newlist
	ss.listMapM <- 1

	reply.Status = storageproto.OK
	return nil
}
开发者ID:karomancer,项目名称:Tribbler,代码行数:52,代码来源:storageimpl.go

示例4: RemoveFromList

func (ss *Storageserver) RemoveFromList(args *storageproto.PutArgs,
	reply *storageproto.PutReply) error {
	lsplog.Vlogf(0, "removeFromList key %s", args.Key)

	//ss.rwlock.Lock()

	val, present := ss.hash[args.Key]
	if !present {
		lsplog.Vlogf(3, "try to remove, key %s does not exist", args.Key)
		reply.Status = storageproto.EKEYNOTFOUND
		//ss.rwlock.Unlock()
		return nil
	}

	entry, present := ss.leasePool[args.Key]

	if present {
		entry.mtx.Lock()
		ss.revokeLeaseHolders(args.Key)

	}

	var list []string
	err := json.Unmarshal([]byte(val), &list)
	if err != nil {
		lsplog.Vlogf(0, "WARNING: unmarshal data generate an error")
	}

	for i, v := range list {
		if v == args.Value {
			list = append(list[:i], list[i+1:]...)

			ss.hash[args.Key], err = json.Marshal(list)
			if err != nil {
				lsplog.Vlogf(0, "WARNING: Marshal data generate an error")
			}

			reply.Status = storageproto.OK
			//ss.rwlock.Unlock()
			return nil
		}
	}

	reply.Status = storageproto.EITEMNOTFOUND
	if present {
		entry.mtx.Unlock()
	}
	//ss.rwlock.Unlock()
	return nil
}
开发者ID:yuguess,项目名称:440_P2,代码行数:50,代码来源:storageimpl.go

示例5: AppendToList

func (ss *Storageserver) AppendToList(args *storageproto.PutArgs, reply *storageproto.PutReply) error {
	//fmt.Println("APPEND TO LIST!")

	//fmt.Println("called appendToList")
	//fmt.Printf("key: %v\n", args.Key)

	rightServer := ss.checkServer(args.Key)

	if rightServer == false {
		reply.Status = storageproto.EWRONGSERVER
		return nil
	}

	//if we are changing something that people have leases on we have to invalidate all leases
	<-ss.leaseMapM
	_, exists := ss.leaseMap[args.Key]
	ss.leaseMapM <- 1

	if exists == true {
		ss.revokeLeases(args.Key)
	}

	//fmt.Println("Unlock lease map!")

	//fmt.Println("Lock list map!")
	<-ss.listMapM
	list, ok := ss.listMap[args.Key]
	if ok == false {
		ss.listMap[args.Key] = []string{}
	}
	ss.listMapM <- 1

	for i := 0; i < len(list); i++ {
		if list[i] == args.Value {
			reply.Status = storageproto.EITEMEXISTS
			return nil
		}
	}
	<-ss.listMapM
	ss.listMap[args.Key] = append(list, args.Value)
	ss.listMapM <- 1

	reply.Status = storageproto.OK
	return nil
}
开发者ID:karomancer,项目名称:Tribbler,代码行数:45,代码来源:storageimpl.go

示例6: Put

func (ss *Storageserver) Put(args *storageproto.PutArgs, reply *storageproto.PutReply) error {
	if !ss.CheckWithinRange(args.Key) {
		reply.Status = storageproto.EWRONGSERVER
		return nil
	}
	ss.modifyingLock.Lock()
	ss.modifying[args.Key] = new(bool)
	ss.modifyingLock.Unlock()
	ss.revokeLeases(args.Key)
	ss.storageLock.Lock()
	ss.storage[args.Key] = new(string)
	*ss.storage[args.Key] = args.Value
	ss.storageLock.Unlock()
	ss.modifyingLock.Lock()
	delete(ss.modifying, args.Key)
	ss.modifyingLock.Unlock()
	reply.Status = storageproto.OK
	return nil
}
开发者ID:ammarar,项目名称:DS-P2,代码行数:19,代码来源:storageimpl.go

示例7: RemoveFromList

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
}
开发者ID:ammarar,项目名称:DS-P2,代码行数:11,代码来源:proxycounter.go

示例8: Put

func (ss *Storageserver) Put(args *storageproto.PutArgs,
	reply *storageproto.PutReply) error {
	var err error

	fmt.Printf("st svr put invoked key %s, val %s !!!\n", args.Key, args.Value)

	//ss.rwlock.Lock()
	if entry, present := ss.leasePool[args.Key]; present {
		fmt.Printf("try to put to %s still lease pool, call revoke!!!\n", args.Key)
		entry.mtx.Lock()
		ss.revokeLeaseHolders(args.Key)
		entry.mtx.Unlock()
	}

	_, present := ss.hash[args.Key]
	if present {
		ss.hash[args.Key], _ = json.Marshal(args.Value)
		reply.Status = storageproto.OK
		//ss.rwlock.Unlock()
		return nil
	}

	if args.Value == "" {
		lsplog.Vlogf(3, "storage first put %s", args.Key)
		ss.hash[args.Key], err = json.Marshal([]string{})
	} else {
		//fmt.Printf("storage put %s, val %s", args.Key, args.Value)
		ss.hash[args.Key], err = json.Marshal(args.Value)
	}

	if err != nil {
		lsplog.Vlogf(0, "WARNING: Marshal data generate an error")
	}

	reply.Status = storageproto.OK

	//ss.rwlock.Unlock()
	//fmt.Println("storage put complete!")
	return nil
}
开发者ID:yuguess,项目名称:440_P2,代码行数:40,代码来源:storageimpl.go

示例9: AppendToList

func (ss *Storageserver) AppendToList(args *storageproto.PutArgs, reply *storageproto.PutReply) error {
	lsplog.Vlogf(1, "Recieved AppendToList request with key=[%v] item=[%v]", args.Key, args.Value)
	if !ss.CheckWithinRange(args.Key) {
		lsplog.Vlogf(1, "[AppendToList] Returning AppendToList with Status EWRONGSERVER")
		reply.Status = storageproto.EWRONGSERVER
		return nil
	}
	lsplog.Vlogf(1, "[AppendToList] Modifying list")
	ss.modifyingListLock.Lock()
	ss.modifyingList[args.Key] = new(bool)
	ss.modifyingListLock.Unlock()
	ss.revokeLeasesList(args.Key)
	ss.storageListLock.Lock()
	lsplog.Vlogf(1, "[AppendToList] Iterating list and looking for duplicates")
	lst := ss.storageList[args.Key]
	if lst == nil {
		ss.storageList[args.Key] = list.New()
		lst = ss.storageList[args.Key]
	} else {
		for e := lst.Front(); e != nil; e = e.Next() {
			if e.Value == args.Value {
				lsplog.Vlogf(1, "[AppendToList] Returning AppendToList with Status EITEMEXISTS")
				reply.Status = storageproto.EITEMEXISTS
				ss.storageListLock.Unlock()
				return nil
			}
		}
	}
	lst.PushBack(args.Value)
	ss.storageListLock.Unlock()
	ss.modifyingListLock.Lock()
	delete(ss.modifyingList, args.Key)
	ss.modifyingListLock.Unlock()
	reply.Status = storageproto.OK
	lsplog.Vlogf(1, "[AppendToList] Returning AppendToList with Status OK")
	return nil
}
开发者ID:ammarar,项目名称:DS-P2,代码行数:37,代码来源:storageimpl.go

示例10: AppendToList

func (ss *Storageserver) AppendToList(args *storageproto.PutArgs,
	reply *storageproto.PutReply) error {

	fmt.Printf("try append %s to list %s\n", args.Value, args.Key)

	//ss.rwlock.Lock()

	_, present := ss.hash[args.Key]
	if !present {
		ss.hash[args.Key] = nil
		/*
		   fmt.Printf("try append %s list with %s, list not exist\n",args.Key, args.Value)
		   reply.Status = storageproto.EKEYNOTFOUND
		   ss.rwlock.Unlock()
		   return nil
		*/
	}

	entry, present := ss.leasePool[args.Key]

	if present {
		//this mutex will ''queue'' later put request while revoking
		entry.mtx.Lock()
		ss.revokeLeaseHolders(args.Key)
	}

	fmt.Printf("storage append to %s list %s\n", args.Key, args.Value)

	var list []string
	err := json.Unmarshal([]byte(ss.hash[args.Key]), &list)
	if err != nil {
		lsplog.Vlogf(0, "WARNING: unmarshal data generate an error")
	}

	//need check duplicate before insertion
	for _, v := range list {
		if v == args.Value {
			reply.Status = storageproto.EITEMEXISTS
			//ss.rwlock.Unlock()
			return nil
		}
	}

	list = append(list, ([]string{args.Value})...)

	ss.hash[args.Key], err = json.Marshal(list)
	if err != nil {
		lsplog.Vlogf(0, "WARNING: Marshal data generate an error")
	}

	reply.Status = storageproto.OK

	fmt.Printf("comp apd %s to %s,val %s\n", args.Value, args.Key, ss.hash[args.Key])

	//ss.rwlock.Unlock()
	if present {
		entry.mtx.Unlock()
	}

	return nil
}
开发者ID:yuguess,项目名称:440_P2,代码行数:61,代码来源:storageimpl.go


注:本文中的P2-f12/official/storageproto.PutReply类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。