Beispiel #1
0
// InternalSnapshotCopy scans the key range specified by start key through
// end key up to some maximum number of results from the given snapshot_id.
// It will create a snapshot if snapshot_id is empty.
func (r *Range) InternalSnapshotCopy(args *proto.InternalSnapshotCopyRequest, reply *proto.InternalSnapshotCopyResponse) {
	if len(args.SnapshotId) == 0 {
		candidateID, err := engine.Increment(r.engine, engine.KeyLocalSnapshotIDGenerator, 1)
		if err != nil {
			reply.SetGoError(err)
			return
		}
		snapshotID := strconv.FormatInt(candidateID, 10)
		err = r.engine.CreateSnapshot(snapshotID)
		if err != nil {
			reply.SetGoError(err)
			return
		}
		args.SnapshotId = snapshotID
	}

	kvs, err := r.engine.ScanSnapshot(args.Key, args.EndKey, args.MaxResults, args.SnapshotId)
	if err != nil {
		reply.SetGoError(err)
		return
	}
	if len(kvs) == 0 {
		err = r.engine.ReleaseSnapshot(args.SnapshotId)
	}

	reply.Rows = kvs
	reply.SnapshotId = args.SnapshotId
	reply.SetGoError(err)
}
Beispiel #2
0
// InternalSnapshotCopy scans the key range specified by start key through
// end key up to some maximum number of results from the given snapshot_id.
// It will create a snapshot if snapshot_id is empty.
func (r *Range) InternalSnapshotCopy(args *proto.InternalSnapshotCopyRequest, reply *proto.InternalSnapshotCopyResponse) {
	if len(args.SnapshotId) == 0 {
		snapshotID, err := r.createSnapshot()
		if err != nil {
			reply.SetGoError(err)
			return
		}
		args.SnapshotId = snapshotID
	}

	kvs, err := r.engine.ScanSnapshot(args.Key, args.EndKey, args.MaxResults, args.SnapshotId)
	if err != nil {
		reply.SetGoError(err)
		return
	}
	if len(kvs) == 0 {
		err = r.engine.ReleaseSnapshot(args.SnapshotId)
	}

	reply.Rows = kvs
	reply.SnapshotId = args.SnapshotId
	reply.SetGoError(err)
}