本文整理汇总了Golang中P2-f12/official/storageproto.PutReply.Status方法的典型用法代码示例。如果您正苦于以下问题:Golang PutReply.Status方法的具体用法?Golang PutReply.Status怎么用?Golang PutReply.Status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类P2-f12/official/storageproto.PutReply
的用法示例。
在下文中一共展示了PutReply.Status方法的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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}