Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Create new shards during domain creation
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbelvin committed Sep 25, 2018
1 parent 7584613 commit b0d86e4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cmd/keytransparency-sequencer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func main() {
keygen := func(ctx context.Context, spec *keyspb.Specification) (proto.Message, error) {
return der.NewProtoFromSpec(spec)
}
adminServer := adminserver.New(tlog, tmap, logAdmin, mapAdmin, domainStorage, keygen)
adminServer := adminserver.New(tlog, tmap, logAdmin, mapAdmin, domainStorage, mutations, keygen)
glog.Infof("Signer starting")

// Run servers
Expand Down
41 changes: 29 additions & 12 deletions core/adminserver/admin_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,21 @@ var (
}
)

// QueueAdmin controls the lifecycle and scaling of mutation queues.
type QueueAdmin interface {
// AddShards creates and adds new shards for queue writing to a domain.
AddShards(ctx context.Context, domainID string, shardIDs ...int64) error
}

// Server implements pb.KeyTransparencyAdminServer
type Server struct {
tlog tpb.TrillianLogClient
tmap tpb.TrillianMapClient
logAdmin tpb.TrillianAdminClient
mapAdmin tpb.TrillianAdminClient
domains domain.Storage
keygen keys.ProtoGenerator
tlog tpb.TrillianLogClient
tmap tpb.TrillianMapClient
logAdmin tpb.TrillianAdminClient
mapAdmin tpb.TrillianAdminClient
domains domain.Storage
queueAdmin QueueAdmin
keygen keys.ProtoGenerator
}

// New returns a KeyTransparencyAdmin implementation.
Expand All @@ -91,15 +98,17 @@ func New(
tmap tpb.TrillianMapClient,
logAdmin, mapAdmin tpb.TrillianAdminClient,
domains domain.Storage,
queueAdmin QueueAdmin,
keygen keys.ProtoGenerator,
) *Server {
return &Server{
tlog: tlog,
tmap: tmap,
logAdmin: logAdmin,
mapAdmin: mapAdmin,
domains: domains,
keygen: keygen,
tlog: tlog,
tmap: tmap,
logAdmin: logAdmin,
mapAdmin: mapAdmin,
domains: domains,
queueAdmin: queueAdmin,
keygen: keygen,
}
}

Expand Down Expand Up @@ -249,6 +258,7 @@ func (s *Server) CreateDomain(ctx context.Context, in *pb.CreateDomainRequest) (
err, logTree.TreeId, delLogErr, mapTree.TreeId, delMapErr)
}

// Create domain - {log, map} binding.
if err := s.domains.Write(ctx, &domain.Domain{
DomainID: in.GetDomainId(),
MapID: mapTree.TreeId,
Expand All @@ -260,6 +270,13 @@ func (s *Server) CreateDomain(ctx context.Context, in *pb.CreateDomainRequest) (
}); err != nil {
return nil, fmt.Errorf("adminserver: domains.Write(): %v", err)
}

// Create shards for queue.
shardIDs := []int64{1}
if err := s.queueAdmin.AddShards(ctx, in.GetDomainId(), shardIDs...); err != nil {
return nil, fmt.Errorf("adminserver: AddShards(%v): %v", shardIDs, err)
}

d := &pb.Domain{
DomainId: in.GetDomainId(),
Log: logTree,
Expand Down
12 changes: 9 additions & 3 deletions core/adminserver/admin_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ func (e *miniEnv) Close() {
e.stopMockServer()
}

type fakeQueueAdmin struct{}

func (*fakeQueueAdmin) AddShards(ctx context.Context, domainID string, shardIDs ...int64) error {
return nil
}

func TestCreateDomain(t *testing.T) {
for _, tc := range []struct {
desc string
Expand Down Expand Up @@ -171,7 +177,7 @@ func TestCreateRead(t *testing.T) {
t.Fatalf("Failed to create trillian log server: %v", err)
}

svr := New(logEnv.Log, mapEnv.Map, logEnv.Admin, mapEnv.Admin, storage, vrfKeyGen)
svr := New(logEnv.Log, mapEnv.Map, logEnv.Admin, mapEnv.Admin, storage, &fakeQueueAdmin{}, vrfKeyGen)

for _, tc := range []struct {
domainID string
Expand Down Expand Up @@ -223,7 +229,7 @@ func TestDelete(t *testing.T) {
t.Fatalf("Failed to create trillian log server: %v", err)
}

svr := New(logEnv.Log, mapEnv.Map, logEnv.Admin, mapEnv.Admin, storage, vrfKeyGen)
svr := New(logEnv.Log, mapEnv.Map, logEnv.Admin, mapEnv.Admin, storage, &fakeQueueAdmin{}, vrfKeyGen)

for _, tc := range []struct {
domainID string
Expand Down Expand Up @@ -287,7 +293,7 @@ func TestListDomains(t *testing.T) {
t.Fatalf("Failed to create trillian log server: %v", err)
}

svr := New(logEnv.Log, mapEnv.Map, logEnv.Admin, mapEnv.Admin, storage, vrfKeyGen)
svr := New(logEnv.Log, mapEnv.Map, logEnv.Admin, mapEnv.Admin, storage, &fakeQueueAdmin{}, vrfKeyGen)

for _, tc := range []struct {
domainIDs []string
Expand Down
10 changes: 5 additions & 5 deletions impl/integration/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ func NewEnv(ctx context.Context) (*Env, error) {
if err != nil {
return nil, fmt.Errorf("env: failed to create domain storage: %v", err)
}
adminSvr := adminserver.New(logEnv.Log, mapEnv.Map, logEnv.Admin, mapEnv.Admin, domainStorage, vrfKeyGen)
mutations, err := mutationstorage.New(db)
if err != nil {
return nil, fmt.Errorf("env: Failed to create mutations object: %v", err)
}
adminSvr := adminserver.New(logEnv.Log, mapEnv.Map, logEnv.Admin, mapEnv.Admin, domainStorage, mutations, vrfKeyGen)
cctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
domainPB, err := adminSvr.CreateDomain(cctx, &pb.CreateDomainRequest{
Expand All @@ -158,10 +162,6 @@ func NewEnv(ctx context.Context) (*Env, error) {
glog.V(5).Infof("Domain: %# v", pretty.Formatter(domainPB))

// Common data structures.
mutations, err := mutationstorage.New(db)
if err != nil {
return nil, fmt.Errorf("env: Failed to create mutations object: %v", err)
}
authFunc := authentication.FakeAuthFunc
authz := &authorization.AuthzPolicy{}

Expand Down

0 comments on commit b0d86e4

Please sign in to comment.