Пример #1
0
func (ls *libstore) deletelist() {
	now := time.Now()
	// ls.mutex.Lock()
	// // fmt.Println("deleteinvalid")
	// defer ls.mutex.Unlock()

	for key, list := range ls.keyValudhistory {
		ls.initiateKeyValueMutex(key)
		ls.keyValueMutex[key].Lock()
		for list.Len() > 0 {
			e := list.Front()
			if e.Value.(time.Time).Add(time.Duration(storagerpc.QueryCacheSeconds)*time.Second).After(now) && list.Len() <= storagerpc.QueryCacheThresh {
				break
			}
			list.Remove(list.Front())
		}
		ls.keyValueMutex[key].Unlock()
	}

	for key, list := range ls.keyListhistory {
		ls.initiateKeyListMutex(key)
		ls.keyListMutex[key].Lock()
		for list.Len() > 0 {
			e := list.Front()
			if e.Value.(time.Time).Add(time.Duration(storagerpc.QueryCacheSeconds)*time.Second).After(now) && list.Len() <= storagerpc.QueryCacheThresh {
				break
			}
			list.Remove(list.Front())
		}
		ls.keyListMutex[key].Unlock()
	}
}
Пример #2
0
func expandClass(regex []int) string {
	list := New()
	list.Init()
	nextEscape := false
	escaped := false
	var toDelete *Element
	for reg_index := 0; reg_index < len(regex); reg_index++ {
		escaped = nextEscape
		nextEscape = false
		switch regex[reg_index] {
		case '\\':
			if escaped {
				escaped = false
				list.PushBack(int('\\'))
				toDelete = nil
			} else {
				nextEscape = true
				toDelete = list.PushBack(int('\\'))
			}
			break
		case '-':
			if escaped {
				escaped = false
				list.PushBack(int('-'))
				toDelete.Value = Delete
			} else {
				if reg_index > 0 && reg_index < len(regex)-1 {
					start := regex[reg_index-1]
					end := uint8(regex[reg_index+1])
					for char := uint8(start + 1); char < end; char++ {
						list.PushBack(int(char))
					}
				} else {
					//ERROR
					fmt.Println("invalid character class")
				}
			}
			break
		default:
			list.PushBack(regex[reg_index])
			break
		}
	}
	for e := list.Front(); e != nil; e = e.Next() {
		if e.Value.(int) == Delete {
			list.Remove(e)
		}
	}
	out := string(list.Remove(list.Front()).(int))
	for e := list.Front(); e != nil; e = e.Next() {
		out += string('|')
		out += string(e.Value.(int))
	}
	return out
}
Пример #3
0
// RemoveAt attempts to remove the value v at the given logical index i. The
// return value v is the item that was found at i. If i is out of bounds, then
// v is set to nil and exists will be false. Otherwise, exists will be true.
func (s *GapSlice) RemoveAt(i int) (v interface{}, exists bool) {
	list := s.list

	e, offset := s.locate(i)
	if e == nil {
		return nil, false
	}

	// The given index is within a gap slice chunk.
	if slice, isSlice := e.Value.(gapSliceChunk); isSlice {
		v = slice[offset]
		// If the index is at the beginning or end of the chunk, simply reslice.
		// Else, split the chunk.
		switch offset {
		case 0:
			e.Value = slice[1:]
		case len(slice) - 1:
			e.Value = slice[:len(slice)-1]
		default:
			a, b := slice[:offset], slice[offset+1:]
			e.Value = a
			list.InsertAfter(b, e)
		}
		s.size -= 1
		return v, true
	}

	v = list.Remove(e)
	s.size -= 1
	return v, true
}
Пример #4
0
// Commit causes all requests that have been queued for the transaction
// to be sent to the request channel for processing. Calls the commit
// function (commitFunc) in order for each request that is part of the
// transaction.
func (txs *txStore) Commit(tx string, commitFunc func(f *frame.Frame) error) error {
	if list, ok := txs.transactions[tx]; ok {
		for element := list.Front(); element != nil; element = list.Front() {
			err := commitFunc(list.Remove(element).(*frame.Frame))
			if err != nil {
				return err
			}
		}
		delete(txs.transactions, tx)
		return nil
	}
	return txUnknown
}
Пример #5
0
func (stack *Stack) Pop() []byte {
	list := (*list.List)(stack)
	el := list.Front()
	if el == nil {
		return nil
	}
	val, ok := el.Value.([]byte)
	if !ok {
		panic("Why is it not a byte array?")
	}
	list.Remove(el)
	return val
}
Пример #6
0
func (h *hashMap) Remove(key Value) (Value, error) {
	index := h.getIndex(key)
	if h.data[index] == nil {
		return nil, fmt.Errorf("not found")
	}
	list := h.data[index]
	for e := list.Front(); e != nil; e = e.Next() {
		if i := e.Value.(*item); i.key.Get() == key.Get() {
			removed := list.Remove(e)
			h.size--
			return removed.(*item).value, nil
		}
	}
	return nil, fmt.Errorf("not found")
}
Пример #7
0
// Remove a service definition from the list. If a service has been removed,
// return true. Different connections cannot remove services they did not add.
func (l *serviceList) Remove(service *ServiceDef) bool {
	list := (*list.List)(l)
	for iter := list.Front(); iter != nil; iter = iter.Next() {
		e := iter.Value.(*ServiceDef)
		res := service.compare(e)
		if res > 0 {
			continue
		} else if res == 0 && e.connId == service.connId {
			list.Remove(iter)
			return true
		}
		// Did not find the service.
		break
	}
	return false
}
Пример #8
0
func (ls *libstore) GetList(key string) ([]string, error) {
	now := time.Now()
	ls.initiateKeyListMutex(key)
	ls.keyListMutex[key].Lock()
	defer ls.keyListMutex[key].Unlock()

	value, ok := ls.keylist[key]

	if ok {
		validUntil := value.lease.startFrom.Add(time.Duration(value.lease.validSeconds) * time.Second)

		if now.After(validUntil) {
			delete(ls.keylist, key)
			ok = !ok
		}
	}
	list, list_ok := ls.keyListhistory[key]
	if list_ok {
		for list.Len() > 0 {
			e := list.Front()
			pretime := e.Value.(time.Time)
			judgetime := pretime.Add(time.Duration(storagerpc.QueryCacheSeconds) * time.Second)
			if judgetime.After(now) && list.Len() <= storagerpc.QueryCacheThresh {
				break
			}
			list.Remove(list.Front())
		}

		list.PushBack(now) // do not know wether count cache or not
	}
	if ok { //use cache
		return value.list, nil
	} else { // use the storage

		want := false
		if ls.mode == Always {
			want = true
		}
		if ls.mode == Normal && list_ok && ls.keyListhistory[key].Len() >= storagerpc.QueryCacheThresh {
			want = true
		}

		args := &storagerpc.GetArgs{
			Key:       key,
			WantLease: want,
			HostPort:  ls.myHostPort,
		}
		reply := &storagerpc.GetListReply{}

		server := ls.Findshashring(key)
		client, ok := ls.clientmap[server]
		if !ok {

			clienttemp, err := rpc.DialHTTP("tcp", server)
			if err != nil {
				return nil, errors.New("meet error when DialHTTP")
			}
			ls.clientmap[server] = clienttemp
			client = clienttemp
		}

		err := client.Call("StorageServer.GetList", args, &reply)
		if err != nil {

			return nil, errors.New("error when libstore call get to storageserver")
		}

		if reply.Status == storagerpc.OK {
			if reply.Lease.Granted == true { // update cache
				ls.keylist[key] = &listlib{
					list: reply.Value,
					lease: leasetype{
						startFrom:    now,
						validSeconds: reply.Lease.ValidSeconds,
					},
				}
			}
		} else if reply.Status == storagerpc.KeyNotFound {
			return make([]string, 0), nil
		} else {
			return nil, errors.New("reply not ready getlist: " + string(reply.Status))
		}
		return reply.Value, nil
	}
}
Пример #9
0
func (node *Node) Delete() interface{} {
	list := node.NodeFather.ChildEle
	return list.Remove(node.NodeAdd)
}