本文整理汇总了Golang中github.com/cmu440/tribbler/rpc/storagerpc.PutReply.Status方法的典型用法代码示例。如果您正苦于以下问题:Golang PutReply.Status方法的具体用法?Golang PutReply.Status怎么用?Golang PutReply.Status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cmu440/tribbler/rpc/storagerpc.PutReply
的用法示例。
在下文中一共展示了PutReply.Status方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RemoveFromList
// RemoveFromList retrieves the specified key from the data store and removes
// the specified value from its list. If the key does not fall within the
// receiving server's range, it should reply with status WrongServer. If
// the specified value is not already contained in the list, it should reply
// with status ItemNotFound.
func (ss *storageServer) RemoveFromList(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
// fmt.Println("RemoveFromList function called:", args);
if FindPartitionNode(ss.ring, args.Key).NodeID != ss.nodeID {
reply.Status = storagerpc.WrongServer
return nil
}
ss.sMutex.Lock()
data, ok := ss.storage[args.Key]
ss.sMutex.Unlock()
if !ok {
reply.Status = storagerpc.KeyNotFound
} else {
data.dMutex.Lock()
list := data.data.([]string)
index := ss.ListContains(list, args.Value)
if index == -1 {
reply.Status = storagerpc.ItemNotFound
} else {
reply.Status = storagerpc.OK
ss.RevokeCallBacksForKey(args.Key, data)
list = append(list[:index], list[index+1:]...)
data.data = list
}
data.dMutex.Unlock()
}
return nil
}
示例2: Put
func (ss *storageServer) Put(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
key := args.Key
if !correctServer(ss, key) {
reply.Status = storagerpc.WrongServer
return nil
}
leases := getLeases(ss, key)
if leases != nil {
ss.editLock.Lock()
revokeLease(ss, key)
ss.editLock.Unlock()
}
ss.valMapLock.Lock()
defer ss.valMapLock.Unlock()
value := args.Value
ss.valMap[key] = value
reply.Status = storagerpc.OK
return nil
}
示例3: Put
/// TODO: add the lease function
func (ss *storageServer) Put(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
// fmt.Println("Put function is called.", args);
if FindPartitionNode(ss.ring, args.Key).NodeID != ss.nodeID {
reply.Status = storagerpc.WrongServer
return nil
}
ss.sMutex.Lock()
data, ok := ss.storage[args.Key]
if ok {
ss.sMutex.Unlock()
// fmt.Println("Put function called: Update a value")
reply.Status = storagerpc.OK
// need to deal with the revoke
data.dMutex.Lock()
ss.RevokeCallBacksForKey(args.Key, data)
// apply changes
// note that the data might be already deleted, so not in the storage map..
data.data = args.Value
data.dMutex.Unlock()
} else {
// fmt.Println("Put function called: Insert a value")
reply.Status = storagerpc.OK
data = &dataUnit{data: args.Value, Set: nil}
ss.storage[args.Key] = data
ss.sMutex.Unlock()
}
return nil
}
示例4: Put
func (ss *storageServer) Put(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
if ss.isReady == false {
reply.Status = storagerpc.NotReady
} else {
if ss.getServerID(args.Key) != ss.nodeID {
reply.Status = storagerpc.WrongServer
return nil
}
ss.serverMutex.Lock()
if ss.userValueMutex[args.Key] == nil {
ss.userValueMutex[args.Key] = &sync.Mutex{}
}
ss.serverMutex.Unlock()
ss.userValueMutex[args.Key].Lock()
defer ss.userValueMutex[args.Key].Unlock()
_, exist := ss.userValue[args.Key]
newMap := make(map[string]*lease)
if exist == true {
for k, v := range ss.userValueLease[args.Key] {
newMap[k] = v
}
// revoke all leases if already exist in server before
err := ss.revokeLease(args.Key, newMap)
if err != nil {
return err
}
}
// make new lease map
ss.userValueLease[args.Key] = make(map[string]*lease)
ss.userValue[args.Key] = args.Value
}
reply.Status = storagerpc.OK
return nil
}
示例5: RemoveFromList
func (ss *storageServer) RemoveFromList(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
status, ok := ss.assertKeyAndServer(args.Key)
if !ok {
reply.Status = status
return nil
}
ss.rwl.Lock()
defer ss.rwl.Unlock()
ss.waitForRevoking(args.Key)
if _, exisit := ss.store[args.Key]; !exisit {
reply.Status = storagerpc.KeyNotFound
return nil
}
// test item exisitence
l := ss.store[args.Key].(*list.List)
for e := l.Front(); e != nil; e = e.Next() {
if e.Value.(string) == args.Value {
ss.revokeLease(args.Key)
l.Remove(e)
reply.Status = storagerpc.OK
return nil
}
}
// item not found
reply.Status = storagerpc.ItemNotFound
return nil
}
示例6: Put
func (ss *storageServer) Put(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
//fmt.Println("Put value: ", args.Value, " to key ", args.Key)
if !ss.IsKeyInRange(args.Key) {
reply.Status = storagerpc.WrongServer
return nil
}
ss.lockForTableLocks.Lock()
/* Lock table for writing */
lock, exist := ss.tableLocks[args.Key]
if !exist {
lock = new(sync.Mutex)
ss.tableLocks[args.Key] = lock
}
ss.lockForTableLocks.Unlock()
lock.Lock()
defer lock.Unlock()
ss.RevokeLease(args.Key)
ss.stringTable[args.Key] = args.Value
reply.Status = storagerpc.OK
return nil
}
示例7: AppendToList
func (ss *storageServer) AppendToList(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
if args == nil {
return errors.New("ss: Can't append nil K/V pair")
}
if reply == nil {
return errors.New("ss: Can't reply with nil in Append")
}
if !(ss.CheckKeyInRange(args.Key)) {
reply.Status = storagerpc.WrongServer
return nil
}
ss.sMutex.Lock()
keyLock, exist := ss.keyLockMap[args.Key]
if !exist {
// Create new lock for the key
keyLock = &sync.Mutex{}
ss.keyLockMap[args.Key] = keyLock
}
ss.sMutex.Unlock()
keyLock.Lock()
defer keyLock.Unlock()
hpTimeMap, leaseExists := ss.leaseMap[args.Key]
if leaseExists {
// Revoke all issued leases.
successChan := make(chan int, 1)
finishChan := make(chan int, 1)
expected := len(ss.leaseMap[args.Key])
go ss.CheckRevokeStatus(args.Key, successChan, finishChan, expected)
for hp, _ := range hpTimeMap {
go ss.RevokeLeaseAt(hp, args.Key, successChan)
}
<-finishChan
delete(ss.leaseMap, args.Key)
}
lst, ok := ss.lMap[args.Key]
if ok {
for _, v := range lst.value {
if v == args.Value {
reply.Status = storagerpc.ItemExists
return nil
}
}
lst.value = append(lst.value, args.Value)
} else {
newValue := lValue{
value: make([]string, 1),
}
newValue.value[0] = args.Value
ss.lMap[args.Key] = &newValue
}
reply.Status = storagerpc.OK
return nil
}
示例8: RemoveFromList
func (ss *storageServer) RemoveFromList(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
if args == nil {
return errors.New("ss: Can't Reomove nil K/V pair")
}
if reply == nil {
return errors.New("ss: Can't reply with nil in Remove")
}
if !(ss.CheckKeyInRange(args.Key)) {
reply.Status = storagerpc.WrongServer
return nil
}
ss.sMutex.Lock()
keyLock, exist := ss.keyLockMap[args.Key]
if !exist {
// Create new lock for the key
keyLock = &sync.Mutex{}
ss.keyLockMap[args.Key] = keyLock
}
ss.sMutex.Unlock()
keyLock.Lock()
defer keyLock.Unlock()
hpTimeMap, leaseExists := ss.leaseMap[args.Key]
if leaseExists {
// Revoke all issued leases.
successChan := make(chan int, 1)
finishChan := make(chan int, 1)
expected := len(ss.leaseMap[args.Key])
go ss.CheckRevokeStatus(args.Key, successChan, finishChan, expected)
for hp, _ := range hpTimeMap {
go ss.RevokeLeaseAt(hp, args.Key, successChan)
}
<-finishChan
delete(ss.leaseMap, args.Key)
}
lst, ok := ss.lMap[args.Key]
if ok {
for i, v := range lst.value {
if v == args.Value {
lst.value = append(lst.value[:i], lst.value[i+1:]...)
reply.Status = storagerpc.OK
return nil
}
}
}
reply.Status = storagerpc.ItemNotFound
return nil
}
示例9: AppendToList
func (ss *storageServer) AppendToList(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
key := args.Key
if rightStorageServer(ss, key) == false {
reply.Status = storagerpc.WrongServer
ss.keyLocks[key] <- 1
return nil
}
if _, found := ss.keyLocks[key]; found == false {
ss.keyLocks[key] = make(chan int, 1)
} else {
<-ss.keyLocks[key]
}
if lst, found := ss.topMap[key]; found {
if l, ok := lst.([]string); ok {
for i := 0; i < len(l); i++ {
if l[i] == args.Value {
// value was already in list
reply.Status = storagerpc.ItemExists
ss.keyLocks[key] <- 1
return nil
}
}
// value was not in list, append to the end
reply.Status = storagerpc.OK
ss.topMap[key] = append(l, args.Value)
} else {
// list was corrputed, shouldn't happen
ss.keyLocks[key] <- 1
return errors.New("List to remove from is wrong type")
}
} else {
// This key hasn't had a list made yet, make new list and insert value
l := make([]string, 1)
l[0] = args.Value
ss.topMap[key] = l
reply.Status = storagerpc.OK
}
ss.keyLocks[key] <- 1
return nil
}
示例10: Put
func (ss *storageServer) Put(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
if !ss.isInServerRange(args.Key) {
reply.Status = storagerpc.WrongServer
return nil
}
//get the lock for current key
ss.mutex.Lock()
lock, exist := ss.lockMap[args.Key]
if !exist {
lock = new(sync.Mutex)
ss.lockMap[args.Key] = lock
}
ss.mutex.Unlock()
//Lock current key we are going to work on
lock.Lock()
//If has granted lease for current key, then revoke all the lease
_, exist = ss.leaseMap[args.Key]
if exist {
//revoke all the granted Lease
finishRevokeChan := make(chan struct{})
singleRevokeChan := make(chan struct{})
leaseHolderList := ss.leaseMap[args.Key]
//revokeNum := leaseHolderList.Len()
go ss.revokeHandler(args.Key, singleRevokeChan, finishRevokeChan)
for e := leaseHolderList.Front(); e != nil; e = e.Next() {
leaseHolder := (e.Value).(LeaseRecord)
go ss.revokeLease(leaseHolder.HostPort, args.Key, singleRevokeChan)
}
//wait until all lease holders reply or leases have expired
<-finishRevokeChan
//delete the lease list for the key
delete(ss.leaseMap, args.Key)
}
//modify value
ss.keyValueMap[args.Key] = args.Value
//resume granting lease for that key
lock.Unlock()
reply.Status = storagerpc.OK
return nil
}
示例11: AppendToList
func (ss *storageServer) AppendToList(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
if ss.isReady == false {
reply.Status = storagerpc.NotReady
} else {
if ss.getServerID(args.Key) != ss.nodeID {
reply.Status = storagerpc.WrongServer
return nil
}
ss.serverMutex.Lock()
if ss.userListMutex[args.Key] == nil {
ss.userListMutex[args.Key] = &sync.Mutex{}
}
ss.serverMutex.Unlock()
ss.userListMutex[args.Key].Lock()
defer ss.userListMutex[args.Key].Unlock()
_, exist := ss.userList[args.Key]
if exist == false {
ss.userList[args.Key] = list.New()
ss.userList[args.Key].PushBack(args.Value)
ss.userListLease[args.Key] = make(map[string]*lease)
reply.Status = storagerpc.OK
} else {
// revoke all leases if already exist in server before
err := ss.revokeLease(args.Key, ss.userListLease[args.Key])
if err != nil {
return err
}
ss.userListLease[args.Key] = make(map[string]*lease)
exist = false
for i := ss.userList[args.Key].Front(); i != nil; i = i.Next() {
if i.Value.(string) == args.Value {
exist = true
break
}
}
if exist == true {
reply.Status = storagerpc.ItemExists
} else {
reply.Status = storagerpc.OK
ss.userList[args.Key].PushBack(args.Value)
}
}
}
return nil
}
示例12: Put
func (ss *storageServer) Put(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
if DBG {
fmt.Println("Entered storage server put with key ", args.Key)
}
if !ss.inRange(libstore.StoreHash(args.Key)) {
reply.Status = storagerpc.WrongServer
return nil
}
// Leasing check
ss.leaseLock.Lock()
// If we have not seen this key before, initialize lease tracker
_, ok := ss.pendingMap[args.Key]
if !ok {
ss.pendingMap[args.Key] = &TrackPending{pending: 0, pendingCh: make(chan chan int, 1)}
}
pendingModifications, _ := ss.pendingMap[args.Key]
pendingModifications.pending++
leaseHolders, ok := ss.leaseStore[args.Key]
ss.leaseLock.Unlock()
if pendingModifications.pending > 1 { // Block until it's our turn to modify key
response := make(chan int)
pendingModifications.pendingCh <- response
<-response
}
if ok {
ss.revokeLeases(leaseHolders, args.Key)
}
ss.dataLock.Lock()
ss.dataStore[args.Key] = args.Value
reply.Status = storagerpc.OK
ss.dataLock.Unlock()
pendingModifications.pending--
Loop:
for {
select {
case ch := <-pendingModifications.pendingCh:
ch <- 1
break Loop
default:
break Loop
}
}
return nil
}
示例13: Put
func (ss *storageServer) Put(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
status, ok := ss.assertKeyAndServer(args.Key)
if !ok {
reply.Status = status
return nil
}
ss.rwl.Lock()
defer ss.rwl.Unlock()
ss.waitForRevoking(args.Key)
ss.revokeLease(args.Key)
ss.store[args.Key] = args.Value
reply.Status = storagerpc.OK
return nil
}
示例14: RemoveFromList
func (ss *storageServer) RemoveFromList(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
key := args.Key
if rightStorageServer(ss, key) == false {
reply.Status = storagerpc.WrongServer
return nil
}
if _, found := ss.keyLocks[key]; found == false {
ss.keyLocks[key] = make(chan int, 1)
} else {
<-ss.keyLocks[key]
}
if lst, found := ss.topMap[key]; found {
if l, ok := lst.([]string); ok {
for i := 0; i < len(l); i++ {
if l[i] == args.Value {
// found item in list, remove it and return
reply.Status = storagerpc.OK
ss.topMap[key] = append(l[:i], l[i+1:]...)
ss.keyLocks[key] <- 1
return nil
}
}
// item was not in the list
reply.Status = storagerpc.ItemNotFound
ss.keyLocks[key] <- 1
return nil
} else {
// list was corrupted, shouldn't happen
ss.keyLocks[key] <- 1
return errors.New("List to remove from is wrong type")
}
} else {
reply.Status = storagerpc.KeyNotFound
ss.keyLocks[key] <- 1
return nil
}
}
示例15: Put
func (ss *storageServer) Put(args *storagerpc.PutArgs, reply *storagerpc.PutReply) error {
key := args.Key
if rightStorageServer(ss, key) == false {
reply.Status = storagerpc.WrongServer
return nil
}
if _, found := ss.keyLocks[key]; found == false {
ss.keyLocks[key] = make(chan int, 1)
} else {
<-ss.keyLocks[key]
}
reply.Status = storagerpc.OK
ss.topMap[key] = args.Value
ss.keyLocks[key] <- 1
return nil
}