revert to existing api with panic per jaffee

This commit is contained in:
Todd Gruben 2018-10-17 10:29:58 -05:00
parent 1d102e283d
commit 0df193cf98
6 changed files with 16 additions and 21 deletions

View file

@ -52,7 +52,7 @@ type Holder struct {
// Key/ID translation
translateFile *TranslateFile
NewPrimaryTranslateStore func(interface{}) (TranslateStore, error)
NewPrimaryTranslateStore func(interface{}) TranslateStore
// opened channel is closed once Open() completes.
opened chan struct{}
@ -590,10 +590,7 @@ func (h *Holder) setPrimaryTranslateStore(node *Node) {
if node != nil {
nodeID = node.ID
}
ts, err := h.NewPrimaryTranslateStore(node)
if err != nil {
h.Logger.Printf("setPrimaryTranslateStore: %s", err)
}
ts := h.NewPrimaryTranslateStore(node)
h.translateFile.SetPrimaryStore(nodeID, ts)
}

View file

@ -11,7 +11,6 @@ import (
"strconv"
"github.com/pilosa/pilosa"
"github.com/pkg/errors"
)
// Ensure implementation implements inteface.
@ -26,12 +25,12 @@ type translateStore struct {
// NewTranslateStore returns a new instance of TranslateStore based on node.
// DEPRECATED: Providing a string url to this function is being deprecated. Instead,
// provide a *pilosa.Node.
func NewTranslateStore(node interface{}) (pilosa.TranslateStore, error) {
func NewTranslateStore(node interface{}) pilosa.TranslateStore {
var n *pilosa.Node
switch v := node.(type) {
case string:
if uri, err := pilosa.NewURIFromAddress(v); err != nil {
return nil, errors.Wrap(err, "creating uri")
panic("bad uri for translatestore in deprecated api")
} else {
n = &pilosa.Node{
ID: v,
@ -41,9 +40,9 @@ func NewTranslateStore(node interface{}) (pilosa.TranslateStore, error) {
case *pilosa.Node:
n = v
default:
return nil, errors.New("*pilosa.Node is the only type supported by NewTranslateStore().")
panic("*pilosa.Node is the only type supported by NewTranslateStore().")
}
return &translateStore{node: n}, nil
return &translateStore{node: n}
}
// TranslateColumnsToUint64 is not currently implemented.

View file

@ -42,7 +42,7 @@ func TestTranslateStore_Reader(t *testing.T) {
}
// Connect to server and stream all available data.
store, _ := http.NewTranslateStore(primary.URL())
store := http.NewTranslateStore(primary.URL())
// Wait to ensure writes make it to translate store
time.Sleep(500 * time.Millisecond)
@ -96,7 +96,7 @@ func TestTranslateStore_Reader(t *testing.T) {
// Connect to server and begin streaming.
ctx, cancel := context.WithCancel(context.Background())
store, _ := http.NewTranslateStore(primary.URL())
store := http.NewTranslateStore(primary.URL())
if _, err := store.Reader(ctx, 0); err != nil {
t.Fatal(err)
}
@ -124,11 +124,8 @@ func TestTranslateStore_Reader(t *testing.T) {
primary := test.MustRunCluster(t, 1, []server.CommandOption{opts})[0]
defer primary.Close()
ts, err := http.NewTranslateStore(primary.URL())
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
_, err = ts.Reader(context.Background(), 0)
ts := http.NewTranslateStore(primary.URL())
_, err := ts.Reader(context.Background(), 0)
if err != pilosa.ErrNotImplemented {
t.Fatalf("unexpected error: %s", err)
}

View file

@ -168,7 +168,7 @@ func OptServerPrimaryTranslateStore(store TranslateStore) ServerOption {
}
}
func OptServerPrimaryTranslateStoreFunc(tf func(interface{}) (TranslateStore, error)) ServerOption {
func OptServerPrimaryTranslateStoreFunc(tf func(interface{}) TranslateStore) ServerOption {
return func(s *Server) error {
s.holder.NewPrimaryTranslateStore = tf
@ -237,7 +237,9 @@ func OptServerClusterHasher(h Hasher) ServerOption {
func OptServerTranslateFileMapSize(mapSize int) ServerOption {
return func(s *Server) error {
s.holder.translateFile = NewTranslateFile(OptTranslateFileMapSize(mapSize))
s.holder.translateFile = NewTranslateFile(
OptTranslateFileMapSize(mapSize),
OptTranslateFileLogger(s.logger))
return nil
}
}

View file

@ -696,7 +696,7 @@ func TestClusterTranslator(t *testing.T) {
cluster[0] = test.NewCommandNode(true)
cluster[0].Config.Gossip.Port = "0"
cluster[0].Start()
httpTranslateStore, _ := http.NewTranslateStore(cluster[0].URL())
httpTranslateStore := http.NewTranslateStore(cluster[0].URL())
cluster[1] = test.NewCommandNode(false,
server.OptCommandServerOptions(
pilosa.OptServerPrimaryTranslateStore(httpTranslateStore),

View file

@ -1118,7 +1118,7 @@ var nopTStore TranslateStore = nopTranslateStore{}
// newNopTranslateStore returns a translate store which does nothing. It returns a global
// object to avoid unnecessary allocations.
func newNopTranslateStore(interface{}) (TranslateStore, error) { return nopTStore, nil }
func newNopTranslateStore(interface{}) TranslateStore { return nopTStore }
// nopTranslateStore represents a no-op implementation of the TranslateStore interface.
type nopTranslateStore struct{}