From 1c9db6b84ead40b3ffc81f929de089ff1d515f39 Mon Sep 17 00:00:00 2001 From: Jacques Grove Date: Wed, 19 Aug 2020 18:20:22 -0700 Subject: [PATCH] Remove long-unused memcache and cacheservice Signed-off-by: Jacques Grove --- go/cacheservice/cacheservice.go | 112 ----------- go/memcache/memcache.go | 320 ------------------------------- go/memcache/memcache_test.go | 323 -------------------------------- 3 files changed, 755 deletions(-) delete mode 100644 go/cacheservice/cacheservice.go delete mode 100644 go/memcache/memcache.go delete mode 100644 go/memcache/memcache_test.go diff --git a/go/cacheservice/cacheservice.go b/go/cacheservice/cacheservice.go deleted file mode 100644 index 9a7dbcabaec..00000000000 --- a/go/cacheservice/cacheservice.go +++ /dev/null @@ -1,112 +0,0 @@ -/* -Copyright 2019 The Vitess Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package cacheservice - -import ( - "fmt" - "sync" - "time" -) - -// NewConnFunc is a factory method that creates a CacheService instance -// using given CacheServiceConfig. -type NewConnFunc func(config Config) (CacheService, error) - -var ( - // services stores all supported cache service. - services = make(map[string]NewConnFunc) - - mu sync.Mutex - - // DefaultCacheService decides the default cache service connection. - DefaultCacheService string -) - -// Config carries config data for CacheService. -type Config struct { - Address string - Timeout time.Duration -} - -// Result gives the cached data. -type Result struct { - Key string - Value []byte - Flags uint16 - Cas uint64 -} - -// CacheService defines functions to use a cache service. -type CacheService interface { - // Get returns cached data for given keys. - Get(keys ...string) (results []Result, err error) - // Gets returns cached data for given keys, it is an alternative Get api - // for using with CAS. Gets returns a CAS identifier with the item. If - // the item's CAS value has changed since you Gets'ed it, it will not be stored. - Gets(keys ...string) (results []Result, err error) - // Set sets the value with specified cache key. - Set(key string, flags uint16, timeout uint64, value []byte) (stored bool, err error) - // Add stores the value only if it does not already exist. - Add(key string, flags uint16, timeout uint64, value []byte) (stored bool, err error) - // Replace replaces the value, only if the value already exists, - // for the specified cache key. - Replace(key string, flags uint16, timeout uint64, value []byte) (stored bool, err error) - // Append appends the value after the last bytes in an existing item. - Append(key string, flags uint16, timeout uint64, value []byte) (stored bool, err error) - // Prepend prepends the value before existing value. - Prepend(key string, flags uint16, timeout uint64, value []byte) (stored bool, err error) - // Cas stores the value only if no one else has updated the data since you read it last. - Cas(key string, flags uint16, timeout uint64, value []byte, cas uint64) (stored bool, err error) - // Delete deletes the value for the specified cache key. - Delete(key string) (deleted bool, err error) - // FlushAll purges the entire cache. - FlushAll() (err error) - // Stats returns a list of basic stats. - Stats(argument string) (result []byte, err error) - // Close closes the CacheService - Close() -} - -// Register a db connection. -func Register(name string, fn NewConnFunc) { - mu.Lock() - defer mu.Unlock() - if _, ok := services[name]; ok { - panic(fmt.Sprintf("register a registered key: %s", name)) - } - services[name] = fn -} - -// Connect returns a CacheService using the given config. -func Connect(config Config) (CacheService, error) { - mu.Lock() - defer mu.Unlock() - if DefaultCacheService == "" { - if len(services) == 1 { - for _, fn := range services { - return fn(config) - } - } - panic("there are more than one service connect func " + - "registered but no default cache service has been specified.") - } - fn, ok := services[DefaultCacheService] - if !ok { - panic(fmt.Sprintf("service connect function for given default cache service: %s is not found.", DefaultCacheService)) - } - return fn(config) -} diff --git a/go/memcache/memcache.go b/go/memcache/memcache.go deleted file mode 100644 index f645ac80d5f..00000000000 --- a/go/memcache/memcache.go +++ /dev/null @@ -1,320 +0,0 @@ -/* -Copyright 2019 The Vitess Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package memcache is a client for memcached. -package memcache - -import ( - "bufio" - "fmt" - "io" - "net" - "strconv" - "strings" - "time" - - "vitess.io/vitess/go/cacheservice" -) - -// Connection is the connection to a memcache. -type Connection struct { - conn net.Conn - buffered bufio.ReadWriter - timeout time.Duration -} - -// Connect connects a memcache process. -func Connect(address string, timeout time.Duration) (conn *Connection, err error) { - var network string - if strings.Contains(address, "/") { - network = "unix" - } else { - network = "tcp" - } - var nc net.Conn - nc, err = net.DialTimeout(network, address, timeout) - if err != nil { - return nil, err - } - return &Connection{ - conn: nc, - buffered: bufio.ReadWriter{ - Reader: bufio.NewReader(nc), - Writer: bufio.NewWriter(nc), - }, - timeout: timeout, - }, nil -} - -// Close closes the memcache connection. -func (mc *Connection) Close() { - mc.conn.Close() -} - -// Get returns cached data for given keys. -func (mc *Connection) Get(keys ...string) (results []cacheservice.Result, err error) { - defer handleError(&err) - results = mc.get("get", keys) - return -} - -// Gets returns cached data for given keys, it is an alternative Get api -// for using with CAS. Gets returns a CAS identifier with the item. If -// the item's CAS value has changed since you Gets'ed it, it will not be stored. -func (mc *Connection) Gets(keys ...string) (results []cacheservice.Result, err error) { - defer handleError(&err) - results = mc.get("gets", keys) - return -} - -// Set sets the value with specified cache key. -func (mc *Connection) Set(key string, flags uint16, timeout uint64, value []byte) (stored bool, err error) { - defer handleError(&err) - return mc.store("set", key, flags, timeout, value, 0), nil -} - -// Add stores the value only if it does not already exist. -func (mc *Connection) Add(key string, flags uint16, timeout uint64, value []byte) (stored bool, err error) { - defer handleError(&err) - return mc.store("add", key, flags, timeout, value, 0), nil -} - -// Replace replaces the value, only if the value already exists, -// for the specified cache key. -func (mc *Connection) Replace(key string, flags uint16, timeout uint64, value []byte) (stored bool, err error) { - defer handleError(&err) - return mc.store("replace", key, flags, timeout, value, 0), nil -} - -// Append appends the value after the last bytes in an existing item. -func (mc *Connection) Append(key string, flags uint16, timeout uint64, value []byte) (stored bool, err error) { - defer handleError(&err) - return mc.store("append", key, flags, timeout, value, 0), nil -} - -// Prepend prepends the value before existing value. -func (mc *Connection) Prepend(key string, flags uint16, timeout uint64, value []byte) (stored bool, err error) { - defer handleError(&err) - return mc.store("prepend", key, flags, timeout, value, 0), nil -} - -// Cas stores the value only if no one else has updated the data since you read it last. -func (mc *Connection) Cas(key string, flags uint16, timeout uint64, value []byte, cas uint64) (stored bool, err error) { - defer handleError(&err) - return mc.store("cas", key, flags, timeout, value, cas), nil -} - -// Delete deletes the value for the specified cache key. -func (mc *Connection) Delete(key string) (deleted bool, err error) { - defer handleError(&err) - mc.setDeadline() - // delete [