Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats, stats items and stats slabs added #105

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion memcache/memcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
// CompareAndSwap) failed because the condition was not satisfied.
ErrNotStored = errors.New("memcache: item not stored")

// ErrServer means that a server error occurred.
// ErrServerError means that a server error occurred.
ErrServerError = errors.New("memcache: server error")

// ErrNoStats means that no statistics were available.
Expand All @@ -61,6 +61,10 @@ var (

// ErrNoServers is returned when no servers are configured or available.
ErrNoServers = errors.New("memcache: no servers configured or available")

// ErrDumpDisable is returned when the "stats cachedump" and
// "lru_crawler metadump" commands are disabled.
ErrDumpDisable = errors.New("memcache: cachedump/metadump disabled")
)

const (
Expand Down Expand Up @@ -101,6 +105,7 @@ func legalKey(key string) bool {
var (
crlf = []byte("\r\n")
space = []byte(" ")
colon = []byte(":")
resultOK = []byte("OK\r\n")
resultStored = []byte("STORED\r\n")
resultNotStored = []byte("NOT_STORED\r\n")
Expand Down Expand Up @@ -308,6 +313,10 @@ func (c *Client) onItem(item *Item, fn func(*Client, *bufio.ReadWriter, *Item) e
return nil
}

// FlushAll Invalidates all existing cache items.
//
// This command does not pause the server, as it returns immediately.
// It does not free up or flush memory at all, it just causes all items to expire.
func (c *Client) FlushAll() error {
return c.selector.Each(c.flushAllFromAddr)
}
Expand Down
54 changes: 54 additions & 0 deletions memcache/memcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,41 @@ func testWithClient(t *testing.T, c *Client) {
}
testTouchWithClient(t, c)

// Test stats
if stats, err := c.StatsServers(); err != nil {
t.Errorf("Stats error: %v", err)
} else {
for addr, s := range stats {
if s.Errs != nil {
t.Errorf("Stats server %s errors: %v", addr.String(), s.Errs)
} else if s.ServerErr != nil {
t.Errorf("Stats server error: %s %v", addr.String(), s.ServerErr)

}
}
}
// Test stats item
if stats, err := c.StatsItemsServers(0); err != nil {
t.Errorf("Stats error: %v", err)
} else {
for addr, s := range stats {
if s.ServerErr != nil {
t.Errorf("Stats server %s error: %v", addr.String(), s.ServerErr)
}
}
}

// Test stats item
if stats, err := c.StatsSlabsServers(); err != nil {
t.Errorf("Stats error: %v", err)
} else {
for addr, s := range stats {
if s.ServerErr != nil {
t.Errorf("Stats server %s error: %v", addr.String(), s.ServerErr)
}
}
}

// Test Delete All
err = c.DeleteAll()
checkErr(err, "DeleteAll: %v", err)
Expand All @@ -209,6 +244,25 @@ func testWithClient(t *testing.T, c *Client) {
t.Errorf("post-DeleteAll want ErrCacheMiss, got %v", err)
}


//Sleep to allow the memcache server to refresh
time.Sleep(time.Second * 5)
if stats, err := c.StatsItemsServers(0); err != nil {
t.Errorf("Stats error: %v", err)
} else {
for addr, stats := range stats {
if len(stats.StatsItemsSlabs) != 0 {
keys := []string{}
for _, itemsStats := range stats.StatsItemsSlabs {
for _, k := range itemsStats.Keys {
keys = append(keys, k.Key)
}
}
t.Errorf("post-DeleteAll stats items in server %s has %d item(s), key(s): %v", addr.String(), len(stats.StatsItemsSlabs), keys)
}
}
}

// Test Ping
err = c.Ping()
checkErr(err, "error ping: %s", err)
Expand Down
Loading