本文整理汇总了Golang中github.com/cockroachdb/cockroach/internal/client.Txn.Scan方法的典型用法代码示例。如果您正苦于以下问题:Golang Txn.Scan方法的具体用法?Golang Txn.Scan怎么用?Golang Txn.Scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/internal/client.Txn
的用法示例。
在下文中一共展示了Txn.Scan方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: scanCmd
// scanCmd reads the values from the db from [key, endKey).
func scanCmd(c *cmd, txn *client.Txn, t *testing.T) error {
rows, err := txn.Scan(c.getKey(), c.getEndKey(), 0)
if err != nil {
return err
}
var vals []string
keyPrefix := []byte(fmt.Sprintf("%d.", c.historyIdx))
for _, kv := range rows {
key := bytes.TrimPrefix(kv.Key, keyPrefix)
c.env[string(key)] = kv.ValueInt()
vals = append(vals, fmt.Sprintf("%d", kv.ValueInt()))
}
c.debug = fmt.Sprintf("[%s]", strings.Join(vals, " "))
return nil
}
示例2: allRangeDescriptors
func allRangeDescriptors(txn *client.Txn) ([]roachpb.RangeDescriptor, error) {
// TODO(dan): Iterate with some batch size.
rows, err := txn.Scan(keys.Meta2Prefix, keys.MetaMax, 0)
if err != nil {
return nil, errors.Wrap(err, "unable to scan range descriptors")
}
rangeDescs := make([]roachpb.RangeDescriptor, len(rows))
for i, row := range rows {
if err := row.ValueProto(&rangeDescs[i]); err != nil {
return nil, errors.Wrapf(err, "%s: unable to unmarshal range descriptor", row.Key)
}
}
return rangeDescs, nil
}
示例3: allSQLDescriptors
func allSQLDescriptors(txn *client.Txn) ([]sqlbase.Descriptor, error) {
startKey := roachpb.Key(keys.MakeTablePrefix(keys.DescriptorTableID))
endKey := startKey.PrefixEnd()
// TODO(dan): Iterate with some batch size.
rows, err := txn.Scan(startKey, endKey, 0)
if err != nil {
return nil, errors.Wrap(err, "unable to scan SQL descriptors")
}
sqlDescs := make([]sqlbase.Descriptor, len(rows))
for i, row := range rows {
if err := row.ValueProto(&sqlDescs[i]); err != nil {
return nil, errors.Wrapf(err, "%s: unable to unmarshal SQL descriptor", row.Key)
}
}
return sqlDescs, nil
}
示例4: restoreTable
func restoreTable(
ctx context.Context,
sst engine.RocksDBSstFileReader,
txn *client.Txn,
table *sqlbase.TableDescriptor,
overwrite bool,
) error {
log.Infof(ctx, "Restoring Table %q", table.Name)
tableStartKey := roachpb.Key(sqlbase.MakeIndexKeyPrefix(table, table.PrimaryIndex.ID))
tableEndKey := tableStartKey.PrefixEnd()
existingDesc, err := txn.Get(sqlbase.MakeDescMetadataKey(table.GetID()))
if err != nil {
return err
}
existingData, err := txn.Scan(tableStartKey, tableEndKey, 1)
if err != nil {
return err
}
if existingDesc.Value != nil || len(existingData) > 0 {
if overwrite {
// We're about to Put the descriptor, so don't bother deleting it.
if err := txn.DelRange(tableStartKey, tableEndKey); err != nil {
return err
}
} else {
return errors.Errorf("table %q already exists", table.Name)
}
}
tableDescKey := sqlbase.MakeDescMetadataKey(table.GetID())
if err := txn.Put(tableDescKey, sqlbase.WrapDescriptor(table)); err != nil {
return err
}
return Import(ctx, sst, txn, engine.MVCCKey{Key: tableStartKey}, engine.MVCCKey{Key: tableEndKey})
}