veyron2/storage: Remove overlapping Stat and Entry types.

The veyron2/storage api provided slightly more Go-ish versions
of the Stat and Entry types than veyron2/services/store.
Unfortunately, these small differences required lots of code
to convert back and forth between the two.

This is the first step in simplifying the store client library.
Suprisingly, it required significant changes to the server.
Next step is to replace the transaction model in veyron2/storage.
I also plan to remove veyron/services/store/server/... if I can.

Change-Id: I9af75636be39748de7cf9bf040a437b34bd10c47
diff --git a/examples/boxes/android/src/boxesp2p/main.go b/examples/boxes/android/src/boxesp2p/main.go
index 7174583..9e8680d 100644
--- a/examples/boxes/android/src/boxesp2p/main.go
+++ b/examples/boxes/android/src/boxesp2p/main.go
@@ -76,7 +76,6 @@
 	"veyron2/naming"
 	"veyron2/rt"
 	"veyron2/security"
-	istore "veyron2/services/store"
 	iwatch "veyron2/services/watch"
 	"veyron2/storage"
 	"veyron2/storage/vstore"
@@ -387,10 +386,10 @@
 }
 
 func init() {
-	// Register *store.Entry for WatchGlob.
-	// TODO(tilaks): store.Entry is declared in vdl, vom should register the
+	// Register *storage.Entry for WatchGlob.
+	// TODO(tilaks): storage.Entry is declared in vdl, vom should register the
 	// pointer automatically.
-	vom.Register(&istore.Entry{})
+	vom.Register(&storage.Entry{})
 	runtime.GOMAXPROCS(runtime.NumCPU())
 }
 
diff --git a/examples/stfortune/stfortune/main.go b/examples/stfortune/stfortune/main.go
index 4b4eff1..e4319a0 100644
--- a/examples/stfortune/stfortune/main.go
+++ b/examples/stfortune/stfortune/main.go
@@ -20,7 +20,6 @@
 	"veyron2/context"
 	"veyron2/naming"
 	"veyron2/rt"
-	istore "veyron2/services/store"
 	iwatch "veyron2/services/watch"
 	"veyron2/storage"
 	"veyron2/storage/vstore"
@@ -47,10 +46,10 @@
 func waitForStore(store storage.Store) {
 	ctx := rt.R().NewContext()
 
-	// Register *store.Entry for WatchGlob.
-	// TODO(tilaks): store.Entry is declared in vdl, vom should register the
+	// Register *storage.Entry for WatchGlob.
+	// TODO(tilaks): storage.Entry is declared in vdl, vom should register the
 	// pointer automatically.
-	vom.Register(&istore.Entry{})
+	vom.Register(&storage.Entry{})
 
 	fmt.Printf("Waiting for Store to be initialized with fortune schema...\n")
 	// List of paths to check in store.
@@ -74,8 +73,8 @@
 // runAsWatcher monitors updates to the fortunes in the store and
 // prints out that information.  It does not return.
 func runAsWatcher(store storage.Store, user string) {
-	// TODO(tilaks): remove this when the store.Entry is auto-registered by VOM.
-	vom.Register(&istore.Entry{})
+	// TODO(tilaks): remove this when the storage.Entry is auto-registered by VOM.
+	vom.Register(&storage.Entry{})
 	ctx := rt.R().NewContext()
 
 	// Monitor all new fortunes or only those of a specific user.
diff --git a/services/store/memstore/object.go b/services/store/memstore/object.go
index 3df879f..411b0a2 100644
--- a/services/store/memstore/object.go
+++ b/services/store/memstore/object.go
@@ -69,13 +69,6 @@
 	return nil
 }
 
-// SetAttr changes the attributes of the entry, such as permissions and
-// replication groups.  Attributes are associated with the value, not the
-// path.
-func (o *Object) SetAttr(pid security.PublicID, tr service.Transaction, attrs ...storage.Attr) error {
-	return verror.Internalf("SetAttr not yet implemented")
-}
-
 // Stat returns entry info.
 func (o *Object) Stat(pid security.PublicID, tr service.Transaction) (*storage.Stat, error) {
 	return nil, verror.Internalf("Stat not yet implemented")
diff --git a/services/store/memstore/query/eval_test.go b/services/store/memstore/query/eval_test.go
index e74de10..d261a4e 100644
--- a/services/store/memstore/query/eval_test.go
+++ b/services/store/memstore/query/eval_test.go
@@ -631,11 +631,11 @@
 }
 
 func (it *repeatForeverIterator) Name() string {
-	return fmt.Sprintf("teams/%v", it.entry.Stat.MTime)
+	return fmt.Sprintf("teams/%v", it.entry.Stat.MTimeNS)
 }
 
 func (it *repeatForeverIterator) Next() {
-	it.entry = &storage.Entry{storage.Stat{storage.NewID(), time.Now(), nil}, it.entry.Value}
+	it.entry = &storage.Entry{storage.Stat{storage.NewID(), time.Now().UnixNano(), nil}, it.entry.Value}
 }
 
 func (it *repeatForeverIterator) Snapshot() state.Snapshot {
@@ -657,7 +657,7 @@
 	sn := &mockSnapshot{
 		&repeatForeverIterator{
 			entry: &storage.Entry{
-				storage.Stat{storage.NewID(), time.Now(), nil},
+				storage.Stat{storage.NewID(), time.Now().UnixNano(), nil},
 				dummyTeam,
 			},
 		},
diff --git a/services/store/memstore/store.go b/services/store/memstore/store.go
index bb7ef4a..e181746 100644
--- a/services/store/memstore/store.go
+++ b/services/store/memstore/store.go
@@ -174,9 +174,3 @@
 	}
 	return tr.Commit()
 }
-
-// SetConflictResolver specifies a function to perform conflict resolution.
-// The <ty> represents the IDL name for the type.
-func (st *Store) SetConflictResolver(ty string, r storage.ConflictResolver) {
-	panic("not implemented")
-}
diff --git a/services/store/memstore/testing/util.go b/services/store/memstore/testing/util.go
index 00066f5..5a9f2a9 100644
--- a/services/store/memstore/testing/util.go
+++ b/services/store/memstore/testing/util.go
@@ -12,7 +12,6 @@
 	"veyron2/ipc"
 	"veyron2/naming"
 	"veyron2/security"
-	"veyron2/services/store"
 	"veyron2/services/watch"
 	"veyron2/storage"
 )
@@ -363,7 +362,7 @@
 	if change.State != watch.Exists {
 		t.Fatalf("Expected name to exist: %v", name)
 	}
-	cv, ok := change.Value.(*store.Entry)
+	cv, ok := change.Value.(*storage.Entry)
 	if !ok {
 		t.Fatal("Expected a service Entry")
 	}
diff --git a/services/store/server/object.go b/services/store/server/object.go
index a76a84b..8b6fa31 100644
--- a/services/store/server/object.go
+++ b/services/store/server/object.go
@@ -29,34 +29,10 @@
 
 	_ store.ObjectService = (*object)(nil)
 
-	nullEntry store.Entry
-	nullStat  store.Stat
+	nullEntry storage.Entry
+	nullStat  storage.Stat
 )
 
-func fillServiceStat(result *store.Stat, stat *storage.Stat) {
-	result.ID = stat.ID
-	result.MTimeNS = stat.MTime.UnixNano()
-	result.Attrs = attrsToAnyData(stat.Attrs)
-}
-
-func makeServiceStat(stat *storage.Stat) store.Stat {
-	if stat == nil {
-		return nullStat
-	}
-	var result store.Stat
-	fillServiceStat(&result, stat)
-	return result
-}
-
-func makeServiceEntry(e *storage.Entry) store.Entry {
-	if e == nil {
-		return nullEntry
-	}
-	result := store.Entry{Value: e.Value}
-	fillServiceStat(&result.Stat, &e.Stat)
-	return result
-}
-
 func (o *object) String() string {
 	return o.name
 }
@@ -68,26 +44,6 @@
 	}
 }
 
-func attrsFromAnyData(attrs []vdlutil.Any) ([]storage.Attr, error) {
-	typedAttrs := make([]storage.Attr, len(attrs))
-	for i, x := range attrs {
-		a, ok := x.(storage.Attr)
-		if !ok {
-			return nil, errNotAnAttribute
-		}
-		typedAttrs[i] = a
-	}
-	return typedAttrs, nil
-}
-
-func attrsToAnyData(attrs []storage.Attr) []vdlutil.Any {
-	uattrs := make([]vdlutil.Any, len(attrs))
-	for i, x := range attrs {
-		uattrs[i] = x
-	}
-	return uattrs
-}
-
 // CreateTransaction creates a transaction.
 func (o *object) CreateTransaction(ctx ipc.ServerContext, opts []vdlutil.Any) (string, error) {
 	if o.tid != nullTransactionID {
@@ -116,7 +72,7 @@
 // Get returns the value for the Object.  The value returned is from the
 // most recent mutation of the entry in the Transaction, or from the
 // Transaction's snapshot if there is no mutation.
-func (o *object) Get(ctx ipc.ServerContext) (store.Entry, error) {
+func (o *object) Get(ctx ipc.ServerContext) (storage.Entry, error) {
 	t, err := o.server.findTransaction(ctx, o.tid)
 	if err != nil {
 		return nullEntry, err
@@ -125,20 +81,20 @@
 	if err != nil {
 		return nullEntry, err
 	}
-	return makeServiceEntry(entry), err
+	return *entry, err
 }
 
 // Put modifies the value of the Object.
-func (o *object) Put(ctx ipc.ServerContext, val vdlutil.Any) (store.Stat, error) {
+func (o *object) Put(ctx ipc.ServerContext, val vdlutil.Any) (storage.Stat, error) {
 	t, err := o.server.findTransaction(ctx, o.tid)
 	if err != nil {
 		return nullStat, err
 	}
-	stat, err := o.obj.Put(ctx.RemoteID(), t, interface{}(val))
+	s, err := o.obj.Put(ctx.RemoteID(), t, interface{}(val))
 	if err != nil {
 		return nullStat, err
 	}
-	return makeServiceStat(stat), nil
+	return *s, err
 }
 
 // Remove removes the Object.
@@ -150,32 +106,17 @@
 	return o.obj.Remove(ctx.RemoteID(), t)
 }
 
-// SetAttr changes the attributes of the entry, such as permissions and
-// replication groups.  Attributes are associated with the value, not the
-// path.
-func (o *object) SetAttr(ctx ipc.ServerContext, attrs []vdlutil.Any) error {
-	t, err := o.server.findTransaction(ctx, o.tid)
-	if err != nil {
-		return err
-	}
-	typedAttrs, err := attrsFromAnyData(attrs)
-	if err != nil {
-		return err
-	}
-	return o.obj.SetAttr(ctx.RemoteID(), t, typedAttrs...)
-}
-
 // Stat returns entry info.
-func (o *object) Stat(ctx ipc.ServerContext) (store.Stat, error) {
+func (o *object) Stat(ctx ipc.ServerContext) (storage.Stat, error) {
 	t, err := o.server.findTransaction(ctx, o.tid)
 	if err != nil {
 		return nullStat, err
 	}
-	stat, err := o.obj.Stat(ctx.RemoteID(), t)
+	s, err := o.obj.Stat(ctx.RemoteID(), t)
 	if err != nil {
 		return nullStat, err
 	}
-	return makeServiceStat(stat), nil
+	return *s, err
 }
 
 // Query returns a sequence of objects that match the given query.
@@ -239,52 +180,12 @@
 	return nil
 }
 
-// ChangeBatchStream is an interface for streaming responses of type ChangeBatch.
-type ChangeBatchStream interface {
-	// Send places the item onto the output stream, blocking if there is no buffer
-	// space available.
-	Send(watch.ChangeBatch) error
-}
-
-// entryTransformStream implements GlobWatcherServiceWatchGlobStream and
-// QueryWatcherServiceWatchQueryStream. It wraps a ChangeBatchStream,
-// transforming the value in each change from *storage.Entry to *store.Entry.
-type entryTransformStream struct {
-	delegate ChangeBatchStream
-}
-
-func (s *entryTransformStream) Send(cb watch.ChangeBatch) error {
-	// Copy and transform the ChangeBatch.
-	changes := cb.Changes
-	changesCp := make([]watch.Change, len(changes))
-	cbCp := watch.ChangeBatch{changesCp}
-	for i, changeCp := range changes {
-		if changes[i].Value != nil {
-			entry := changes[i].Value.(*storage.Entry)
-			serviceEntry := makeServiceEntry(entry)
-			changeCp.Value = &serviceEntry
-		}
-		changesCp[i] = changeCp
-	}
-	return s.delegate.Send(cbCp)
-}
-
-func (s *entryTransformStream) SendStream() interface {
-	Send(cb watch.ChangeBatch) error
-} {
-	return s
-}
-
 // WatchGlob returns a stream of changes that match a pattern.
 func (o *object) WatchGlob(ctx ipc.ServerContext, req watch.GlobRequest, stream watch.GlobWatcherServiceWatchGlobStream) error {
-	path := storage.ParsePath(o.name)
-	stream = &entryTransformStream{stream.SendStream()}
-	return o.server.watcher.WatchGlob(ctx, path, req, stream)
+	return o.server.watcher.WatchGlob(ctx, storage.ParsePath(o.name), req, stream)
 }
 
 // WatchQuery returns a stream of changes that satisfy a query.
 func (o *object) WatchQuery(ctx ipc.ServerContext, req watch.QueryRequest, stream watch.QueryWatcherServiceWatchQueryStream) error {
-	path := storage.ParsePath(o.name)
-	stream = &entryTransformStream{stream.SendStream()}
-	return o.server.watcher.WatchQuery(ctx, path, req, stream)
+	return o.server.watcher.WatchQuery(ctx, storage.ParsePath(o.name), req, stream)
 }
diff --git a/services/wsprd/lib/remove_this.go b/services/wsprd/lib/remove_this.go
index 0431f09..266ca2b 100644
--- a/services/wsprd/lib/remove_this.go
+++ b/services/wsprd/lib/remove_this.go
@@ -5,15 +5,16 @@
 	"veyron2/services/mounttable"
 	"veyron2/services/store"
 	"veyron2/services/watch"
+	"veyron2/storage"
 	"veyron2/vom"
 )
 
 func init() {
 	vom.Register(mounttable.MountEntry{})
-	vom.Register(store.Entry{})
+	vom.Register(storage.Entry{})
+	vom.Register(storage.Stat{})
 	vom.Register(store.NestedResult(0))
 	vom.Register(store.QueryResult{})
-	vom.Register(store.Stat{})
 	vom.Register(watch.GlobRequest{})
 	vom.Register(watch.QueryRequest{})
 	vom.Register(watch.ChangeBatch{})