Exemple #1
0
func writeWithReverses(ctx context.Context, tbl *table.KVProto, src, kind string, targets []string) error {
	if err := tbl.Put(ctx, []byte(src+tempTableKeySep+kind+tempTableKeySep), &srvpb.EdgeSet_Group{
		Kind:         kind,
		TargetTicket: targets,
	}); err != nil {
		return fmt.Errorf("error writing edges group: %v", err)
	}
	revGroup := &srvpb.EdgeSet_Group{
		Kind:         schema.MirrorEdge(kind),
		TargetTicket: []string{src},
	}
	for _, tgt := range targets {
		if err := tbl.Put(ctx, []byte(tgt+tempTableKeySep+revGroup.Kind+tempTableKeySep+src), revGroup); err != nil {
			return fmt.Errorf("error writing rev edges group: %v", err)
		}
	}
	return nil
}
Exemple #2
0
func writeEdgePages(ctx context.Context, t table.Proto, edgeGroups *table.KVProto, maxEdgePageSize int) error {
	// TODO(schroederc): spill large PagedEdgeSets into EdgePages

	it, err := edgeGroups.ScanPrefix(nil, &keyvalue.Options{LargeRead: true})
	if err != nil {
		return err
	}
	defer it.Close()

	log.Println("Writing EdgeSets")
	esb := &assemble.EdgeSetBuilder{
		MaxEdgePageSize: maxEdgePageSize,
		Output: func(ctx context.Context, pes *srvpb.PagedEdgeSet) error {
			return t.Put(ctx, xrefs.EdgeSetKey(pes.EdgeSet.SourceTicket), pes)
		},
		OutputPage: func(ctx context.Context, ep *srvpb.EdgePage) error {
			return t.Put(ctx, xrefs.EdgePageKey(ep.PageKey), ep)
		},
	}
	for {
		k, v, err := it.Next()
		if err == io.EOF {
			break
		} else if err != nil {
			return fmt.Errorf("error scanning edge groups table: %v", err)
		}

		ss := strings.Split(string(k), tempTableKeySep)
		if len(ss) != 3 {
			return fmt.Errorf("invalid edge groups table key: %q", string(k))
		}
		src := ss[0]

		var eg srvpb.EdgeSet_Group
		if err := proto.Unmarshal(v, &eg); err != nil {
			return fmt.Errorf("invalid edge groups table value: %v", err)
		}

		if err := esb.AddGroup(ctx, src, &eg); err != nil {
			return err
		}
	}
	return esb.Flush(ctx)
}
Exemple #3
0
func createDecorationFragments(ctx context.Context, edges <-chan *srvpb.Edge, fragments *table.KVProto) error {
	fdb := &assemble.DecorationFragmentBuilder{
		Output: func(ctx context.Context, file string, fragment *srvpb.FileDecorations) error {
			key := file + tempTableKeySep
			if len(fragment.Decoration) != 0 {
				key += fragment.Decoration[0].Anchor.Ticket
			}
			return fragments.Put(ctx, []byte(key), fragment)
		},
	}

	for e := range edges {
		if err := fdb.AddEdge(ctx, e); err != nil {
			for range edges { // drain input channel
			}
			return err
		}
	}

	return fdb.Flush(ctx)
}
Exemple #4
0
func readCompletedEdges(ctx context.Context, edges *table.KVProto, outs ...chan<- *srvpb.Edge) error {
	defer func() {
		for _, out := range outs {
			close(out)
		}
	}()

	snapshot := edges.NewSnapshot()
	defer snapshot.Close()
	it, err := edges.ScanPrefix(nil, &keyvalue.Options{
		LargeRead: true,
		Snapshot:  snapshot,
	})
	if err != nil {
		return err
	}
	defer it.Close()

	for {
		_, v, err := it.Next()
		if err == io.EOF {
			break
		} else if err != nil {
			return fmt.Errorf("error scanning edges table: %v", err)
		}

		var e srvpb.Edge
		if err := proto.Unmarshal(v, &e); err != nil {
			return fmt.Errorf("invalid edge table value: %v", err)
		}

		for _, out := range outs {
			out <- &e
		}
	}

	return nil
}
Exemple #5
0
func writeEdge(ctx context.Context, edges *table.KVProto, e *srvpb.Edge) error {
	return edges.Put(ctx, []byte(e.Source.Ticket+tempTableKeySep+e.Kind+tempTableKeySep+e.Target.Ticket), e)
}