mirror of
https://github.com/minio/minio.git
synced 2025-12-08 08:42:43 -05:00
Enhance the event store interface to support channeling (#7343)
- Avoids code duplication across the other targets. By having a centralized function call. - Reduce the room for race.
This commit is contained in:
committed by
Nitish Tiwari
parent
ddb0d646aa
commit
47ca411163
@@ -57,7 +57,7 @@ func (store *MemoryStore) Put(e event.Event) error {
|
||||
store.Lock()
|
||||
defer store.Unlock()
|
||||
if store.eC == store.limit {
|
||||
return ErrLimitExceeded
|
||||
return errLimitExceeded
|
||||
}
|
||||
key, kErr := getNewUUID()
|
||||
if kErr != nil {
|
||||
@@ -77,27 +77,41 @@ func (store *MemoryStore) Get(key string) (event.Event, error) {
|
||||
return event, nil
|
||||
}
|
||||
|
||||
return event.Event{}, ErrNoSuchKey
|
||||
return event.Event{}, errNoSuchKey
|
||||
}
|
||||
|
||||
// Del - deletes the event from store.
|
||||
func (store *MemoryStore) Del(key string) {
|
||||
func (store *MemoryStore) Del(key string) error {
|
||||
store.Lock()
|
||||
defer store.Unlock()
|
||||
|
||||
delete(store.events, key)
|
||||
|
||||
store.eC--
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListAll - lists all the keys in the store.
|
||||
func (store *MemoryStore) ListAll() []string {
|
||||
// ListN - lists atmost N keys in the store.
|
||||
func (store *MemoryStore) ListN(n int) []string {
|
||||
store.RLock()
|
||||
defer store.RUnlock()
|
||||
|
||||
var i int
|
||||
|
||||
if n == -1 {
|
||||
n = len(store.events)
|
||||
}
|
||||
|
||||
keys := []string{}
|
||||
for k := range store.events {
|
||||
keys = append(keys, k)
|
||||
if i < n {
|
||||
keys = append(keys, k)
|
||||
i++
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return keys
|
||||
|
||||
Reference in New Issue
Block a user