本文整理汇总了Golang中github.com/cockroachdb/cockroach/util/timeutil.Now函数的典型用法代码示例。如果您正苦于以下问题:Golang Now函数的具体用法?Golang Now怎么用?Golang Now使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Now函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: runMVCCConditionalPut
func runMVCCConditionalPut(valueSize int, createFirst bool, b *testing.B) {
rng, _ := randutil.NewPseudoRand()
value := roachpb.MakeValueFromBytes(randutil.RandBytes(rng, valueSize))
keyBuf := append(make([]byte, 0, 64), []byte("key-")...)
stopper := stop.NewStopper()
defer stopper.Stop()
rocksdb := NewInMem(roachpb.Attributes{}, testCacheSize, stopper)
b.SetBytes(int64(valueSize))
var expected *roachpb.Value
if createFirst {
for i := 0; i < b.N; i++ {
key := roachpb.Key(encoding.EncodeUvarintAscending(keyBuf[:4], uint64(i)))
ts := makeTS(timeutil.Now().UnixNano(), 0)
if err := MVCCPut(rocksdb, nil, key, ts, value, nil); err != nil {
b.Fatalf("failed put: %s", err)
}
}
expected = &value
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
key := roachpb.Key(encoding.EncodeUvarintAscending(keyBuf[:4], uint64(i)))
ts := makeTS(timeutil.Now().UnixNano(), 0)
if err := MVCCConditionalPut(rocksdb, nil, key, ts, value, expected, nil); err != nil {
b.Fatalf("failed put: %s", err)
}
}
b.StopTimer()
}
开发者ID:cuongdo,项目名称:cockroach,代码行数:34,代码来源:rocksdb_test.go
示例2: monitor
func (z *zeroSum) monitor(d time.Duration) {
start := timeutil.Now()
lastTime := start
var lastOps uint64
for ticks := 0; true; ticks++ {
time.Sleep(d)
if ticks%20 == 0 {
fmt.Printf("_elapsed__accounts_________ops__ops/sec___errors___splits____xfers___ranges_____________replicas\n")
}
now := timeutil.Now()
elapsed := now.Sub(lastTime).Seconds()
ops := atomic.LoadUint64(&z.stats.ops)
z.ranges.Lock()
ranges, replicas := z.ranges.count, z.ranges.replicas
z.ranges.Unlock()
fmt.Printf("%8s %9d %11d %8.1f %8d %8d %8d %8d %20s\n",
time.Duration(now.Sub(start).Seconds()+0.5)*time.Second,
z.accountsLen(), ops, float64(ops-lastOps)/elapsed,
atomic.LoadUint64(&z.stats.errors),
atomic.LoadUint64(&z.stats.splits),
atomic.LoadUint64(&z.stats.transfers),
ranges, z.formatReplicas(replicas))
lastTime = now
lastOps = ops
}
}
开发者ID:yangxuanjia,项目名称:cockroach,代码行数:31,代码来源:main.go
示例3: testGossipPeeringsInner
func testGossipPeeringsInner(t *testing.T, c cluster.Cluster, cfg cluster.TestConfig) {
num := c.NumNodes()
deadline := timeutil.Now().Add(cfg.Duration)
waitTime := longWaitTime
if cfg.Duration < waitTime {
waitTime = shortWaitTime
}
for timeutil.Now().Before(deadline) {
checkGossip(t, c, waitTime, hasPeers(num))
// Restart the first node.
log.Infof(context.Background(), "restarting node 0")
if err := c.Restart(0); err != nil {
t.Fatal(err)
}
checkGossip(t, c, waitTime, hasPeers(num))
// Restart another node (if there is one).
var pickedNode int
if num > 1 {
pickedNode = rand.Intn(num-1) + 1
}
log.Infof(context.Background(), "restarting node %d", pickedNode)
if err := c.Restart(pickedNode); err != nil {
t.Fatal(err)
}
checkGossip(t, c, waitTime, hasPeers(num))
}
}
开发者ID:yangxuanjia,项目名称:cockroach,代码行数:32,代码来源:gossip_peerings_test.go
示例4: runMVCCConditionalPut
func runMVCCConditionalPut(emk engineMaker, valueSize int, createFirst bool, b *testing.B) {
rng, _ := randutil.NewPseudoRand()
value := roachpb.MakeValueFromBytes(randutil.RandBytes(rng, valueSize))
keyBuf := append(make([]byte, 0, 64), []byte("key-")...)
eng, stopper := emk(b, fmt.Sprintf("cput_%d", valueSize))
defer stopper.Stop()
b.SetBytes(int64(valueSize))
var expected *roachpb.Value
if createFirst {
for i := 0; i < b.N; i++ {
key := roachpb.Key(encoding.EncodeUvarintAscending(keyBuf[:4], uint64(i)))
ts := makeTS(timeutil.Now().UnixNano(), 0)
if err := MVCCPut(context.Background(), eng, nil, key, ts, value, nil); err != nil {
b.Fatalf("failed put: %s", err)
}
}
expected = &value
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
key := roachpb.Key(encoding.EncodeUvarintAscending(keyBuf[:4], uint64(i)))
ts := makeTS(timeutil.Now().UnixNano(), 0)
if err := MVCCConditionalPut(context.Background(), eng, nil, key, ts, value, expected, nil); err != nil {
b.Fatalf("failed put: %s", err)
}
}
b.StopTimer()
}
开发者ID:yaojingguo,项目名称:cockroach,代码行数:33,代码来源:bench_test.go
示例5: AfterTest
// AfterTest snapshots the currently-running goroutines and returns a
// function to be run at the end of tests to see whether any
// goroutines leaked.
func AfterTest(t testing.TB) func() {
orig := map[string]bool{}
for _, g := range interestingGoroutines() {
orig[g] = true
}
return func() {
// Loop, waiting for goroutines to shut down.
// Wait up to 5 seconds, but finish as quickly as possible.
deadline := timeutil.Now().Add(5 * time.Second)
for {
var leaked []string
for _, g := range interestingGoroutines() {
if !orig[g] {
leaked = append(leaked, g)
}
}
if len(leaked) == 0 {
return
}
if timeutil.Now().Before(deadline) {
time.Sleep(50 * time.Millisecond)
continue
}
for _, g := range leaked {
t.Errorf("Leaked goroutine: %v", g)
}
return
}
}
}
开发者ID:petermattis,项目名称:cockroach,代码行数:33,代码来源:leaktest.go
示例6: TestPeekType
func TestPeekType(t *testing.T) {
encodedDurationAscending, _ := EncodeDurationAscending(nil, duration.Duration{})
encodedDurationDescending, _ := EncodeDurationDescending(nil, duration.Duration{})
testCases := []struct {
enc []byte
typ Type
}{
{EncodeNullAscending(nil), Null},
{EncodeNotNullAscending(nil), NotNull},
{EncodeNullDescending(nil), Null},
{EncodeNotNullDescending(nil), NotNull},
{EncodeVarintAscending(nil, 0), Int},
{EncodeVarintDescending(nil, 0), Int},
{EncodeUvarintAscending(nil, 0), Int},
{EncodeUvarintDescending(nil, 0), Int},
{EncodeFloatAscending(nil, 0), Float},
{EncodeFloatDescending(nil, 0), Float},
{EncodeDecimalAscending(nil, inf.NewDec(0, 0)), Decimal},
{EncodeDecimalDescending(nil, inf.NewDec(0, 0)), Decimal},
{EncodeBytesAscending(nil, []byte("")), Bytes},
{EncodeBytesDescending(nil, []byte("")), BytesDesc},
{EncodeTimeAscending(nil, timeutil.Now()), Time},
{EncodeTimeDescending(nil, timeutil.Now()), TimeDesc},
{encodedDurationAscending, Duration},
{encodedDurationDescending, Duration},
}
for i, c := range testCases {
typ := PeekType(c.enc)
if c.typ != typ {
t.Fatalf("%d: expected %d, but found %d", i, c.typ, typ)
}
}
}
开发者ID:bogdanbatog,项目名称:cockroach,代码行数:33,代码来源:encoding_test.go
示例7: TestAdminAPIUIData
func TestAdminAPIUIData(t *testing.T) {
defer leaktest.AfterTest(t)()
s := StartTestServer(t)
defer s.Stop()
start := timeutil.Now()
mustSetUIData := func(key string, val []byte) {
var resp struct{}
b64Val := base64.StdEncoding.EncodeToString(val)
reqBody := fmt.Sprintf(`{"key": "%s", "value": "%s"}`, key, b64Val)
if err := apiPost(s, "uidata", reqBody, &resp); err != nil {
t.Fatal(err)
}
}
expectValueEquals := func(key string, expVal []byte) {
var resp GetUIDataResponse
url := fmt.Sprintf("uidata?key=%s", key)
if err := apiGet(s, url, &resp); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(resp.Value, expVal) {
t.Fatalf("value for key %s = %v != expected %v", key, resp.Value, expVal)
}
// Sanity check LastUpdated.
now := timeutil.Now()
lastUpdated := time.Unix(resp.LastUpdated.Sec, int64(resp.LastUpdated.Nsec))
if lastUpdated.Before(start) {
t.Fatalf("lastUpdated %s < start %s", lastUpdated, start)
}
if lastUpdated.After(now) {
t.Fatalf("lastUpdated %s > now %s", lastUpdated, now)
}
}
expectKeyNotFound := func(key string) {
var resp GetUIDataResponse
url := fmt.Sprintf("uidata?key=%s", key)
expErr := "key " + key + " not found"
if err := apiGet(s, url, &resp); !testutils.IsError(err, expErr) {
t.Fatalf("unexpected error: %s", err)
}
}
// Basic tests.
mustSetUIData("k1", []byte("v1"))
expectValueEquals("k1", []byte("v1"))
expectKeyNotFound("NON_EXISTENT_KEY")
// Write a binary blob with all possible byte values, then verify it.
var buf bytes.Buffer
for i := 0; i < 997; i++ {
buf.WriteByte(byte(i % 256))
}
mustSetUIData("bin", buf.Bytes())
expectValueEquals("bin", buf.Bytes())
}
开发者ID:cuongdo,项目名称:cockroach,代码行数:59,代码来源:admin_test.go
示例8: Execute
// Execute the statement(s) in the given request and returns a response.
// On error, the returned integer is an HTTP error code.
func (e *Executor) Execute(args Request) (Response, int, error) {
defer func(start time.Time) {
e.latency.RecordValue(timeutil.Now().Sub(start).Nanoseconds())
}(timeutil.Now())
results := e.ExecuteStatements(
args.User, args.Session, args.SQL, args.Params)
return Response{Results: results, Session: args.Session}, 0, nil
}
开发者ID:cuongdo,项目名称:cockroach,代码行数:10,代码来源:executor.go
示例9: insertLoad
// insertLoad add a very basic load that inserts into a unique table and checks
// that the inserted values are indeed correct.
func insertLoad(t *testing.T, dc *dynamicClient, ID int) {
// Initialize the db.
if _, err := dc.exec(`CREATE DATABASE IF NOT EXISTS Insert`); err != nil {
t.Fatal(err)
}
tableName := fmt.Sprintf("Insert.Table%d", ID)
createTableStatement := fmt.Sprintf(`
CREATE TABLE %s (
key INT PRIMARY KEY,
value INT NOT NULL
)`, tableName)
insertStatement := fmt.Sprintf(`INSERT INTO %s (key, value) VALUES ($1, $1)`, tableName)
selectStatement := fmt.Sprintf(`SELECT key-value AS "total" FROM %s WHERE key = $1`, tableName)
// Init the db for the basic insert.
if _, err := dc.exec(createTableStatement); err != nil {
t.Fatal(err)
}
var valueCheck, valueInsert int
nextUpdate := timeutil.Now()
// Perform inserts and selects
for dc.isRunning() {
// Insert some values.
valueInsert++
if _, err := dc.exec(insertStatement, valueInsert); err != nil {
if err == errTestFinished {
return
}
t.Fatal(err)
}
// Check that another value is still correct.
valueCheck--
if valueCheck < 1 {
valueCheck = valueInsert
}
var total int
if err := dc.queryRowScan(selectStatement, []interface{}{valueCheck}, []interface{}{&total}); err != nil {
if err == errTestFinished {
return
}
t.Fatal(err)
}
if total != 0 {
t.Fatalf("total expected to be 0, is %d", total)
}
if timeutil.Now().After(nextUpdate) {
log.Infof("Insert %d: inserted and checked %d values", ID, valueInsert)
nextUpdate = timeutil.Now().Add(time.Second)
}
}
}
开发者ID:GitGoldie,项目名称:cockroach,代码行数:60,代码来源:load.go
示例10: Logs
// Logs returns the log entries parsed from the log files stored on
// the server. Log entries are returned in reverse chronological order. The
// following options are available:
// * "starttime" query parameter filters the log entries to only ones that
// occurred on or after the "starttime". Defaults to a day ago.
// * "endtime" query parameter filters the log entries to only ones that
// occurred before on on the "endtime". Defaults to the current time.
// * "pattern" query parameter filters the log entries by the provided regexp
// pattern if it exists. Defaults to nil.
// * "max" query parameter is the hard limit of the number of returned log
// entries. Defaults to defaultMaxLogEntries.
// * "level" query parameter filters the log entries to be those of the
// corresponding severity level or worse. Defaults to "info".
func (s *statusServer) Logs(ctx context.Context, req *serverpb.LogsRequest) (*serverpb.JSONResponse, error) {
log.Flush()
var sev log.Severity
if len(req.Level) == 0 {
sev = log.InfoLog
} else {
var sevFound bool
sev, sevFound = log.SeverityByName(req.Level)
if !sevFound {
return nil, fmt.Errorf("level could not be determined: %s", req.Level)
}
}
startTimestamp, err := parseInt64WithDefault(
req.StartTime,
timeutil.Now().AddDate(0, 0, -1).UnixNano())
if err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, "StartTime could not be parsed: %s", err)
}
endTimestamp, err := parseInt64WithDefault(req.EndTime, timeutil.Now().UnixNano())
if err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, "EndTime could not be parsed: %s", err)
}
if startTimestamp > endTimestamp {
return nil, grpc.Errorf(codes.InvalidArgument, "StartTime: %d should not be greater than endtime: %d", startTimestamp, endTimestamp)
}
maxEntries, err := parseInt64WithDefault(req.Max, defaultMaxLogEntries)
if err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, "Max could not be parsed: %s", err)
}
if maxEntries < 1 {
return nil, grpc.Errorf(codes.InvalidArgument, "Max: %d should be set to a value greater than 0", maxEntries)
}
var regex *regexp.Regexp
if len(req.Pattern) > 0 {
if regex, err = regexp.Compile(req.Pattern); err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, "regex pattern could not be compiled: %s", err)
}
}
entries, err := log.FetchEntriesFromFiles(sev, startTimestamp, endTimestamp, int(maxEntries), regex)
if err != nil {
return nil, err
}
return marshalJSONResponse(entries)
}
开发者ID:yangxuanjia,项目名称:cockroach,代码行数:65,代码来源:status.go
示例11: waitClientsStop
// Wait until all clients have stopped.
func waitClientsStop(num int, state *testState, stallDuration time.Duration) {
prevRound := atomic.LoadUint64(&state.monkeyIteration)
stallTime := timeutil.Now().Add(stallDuration)
var prevOutput string
// Spin until all clients are shut.
for numShutClients := 0; numShutClients < num; {
select {
case <-state.teardown:
case <-stopper:
state.t.Fatal("interrupted")
case err := <-state.errChan:
if err != nil {
state.t.Error(err)
}
numShutClients++
case <-time.After(time.Second):
var newOutput string
if timeutil.Now().Before(state.deadline) {
curRound := atomic.LoadUint64(&state.monkeyIteration)
if curRound == prevRound {
if timeutil.Now().After(stallTime) {
atomic.StoreInt32(&state.stalled, 1)
state.t.Fatalf("Stall detected at round %d, no forward progress for %s", curRound, stallDuration)
}
} else {
prevRound = curRound
stallTime = timeutil.Now().Add(stallDuration)
}
// Periodically print out progress so that we know the test is
// still running and making progress.
counts := state.counts()
strCounts := make([]string, len(counts))
for i := range counts {
strCounts[i] = strconv.FormatUint(counts[i], 10)
}
newOutput = fmt.Sprintf("round %d: client counts: (%s)", curRound, strings.Join(strCounts, ", "))
} else {
newOutput = fmt.Sprintf("test finished, waiting for shutdown of %d clients", num-numShutClients)
}
// This just stops the logs from being a bit too spammy.
if newOutput != prevOutput {
log.Infof(newOutput)
prevOutput = newOutput
}
}
}
}
开发者ID:cuongdo,项目名称:cockroach,代码行数:50,代码来源:chaos_test.go
示例12: RetryForDuration
// RetryForDuration will retry the given function until it either returns
// without error, or the given duration has elapsed. The function is invoked
// immediately at first and then successively with an exponential backoff
// starting at 1ns and ending at the specified duration.
func RetryForDuration(duration time.Duration, fn func() error) error {
deadline := timeutil.Now().Add(duration)
var lastErr error
for wait := time.Duration(1); timeutil.Now().Before(deadline); wait *= 2 {
lastErr = fn()
if lastErr == nil {
return nil
}
if wait > time.Second {
wait = time.Second
}
time.Sleep(wait)
}
return lastErr
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:19,代码来源:testing.go
示例13: testPutInner
func testPutInner(t *testing.T, c cluster.Cluster, cfg cluster.TestConfig) {
db, dbStopper := c.NewClient(t, 0)
defer dbStopper.Stop()
errs := make(chan error, c.NumNodes())
start := timeutil.Now()
deadline := start.Add(cfg.Duration)
var count int64
for i := 0; i < c.NumNodes(); i++ {
go func() {
r, _ := randutil.NewPseudoRand()
value := randutil.RandBytes(r, 8192)
for timeutil.Now().Before(deadline) {
k := atomic.AddInt64(&count, 1)
v := value[:r.Intn(len(value))]
if err := db.Put(fmt.Sprintf("%08d", k), v); err != nil {
errs <- err
return
}
}
errs <- nil
}()
}
for i := 0; i < c.NumNodes(); {
baseCount := atomic.LoadInt64(&count)
select {
case <-stopper:
t.Fatalf("interrupted")
case err := <-errs:
if err != nil {
t.Fatal(err)
}
i++
case <-time.After(1 * time.Second):
// Periodically print out progress so that we know the test is still
// running.
loadedCount := atomic.LoadInt64(&count)
log.Infof(context.Background(), "%d (%d/s)", loadedCount, loadedCount-baseCount)
c.Assert(t)
cluster.Consistent(t, c)
}
}
elapsed := timeutil.Since(start)
log.Infof(context.Background(), "%d %.1f/sec", count, float64(count)/elapsed.Seconds())
}
开发者ID:yangxuanjia,项目名称:cockroach,代码行数:48,代码来源:put_test.go
示例14: stop
// stop stops the cluster.
func (l *LocalCluster) stop() {
if *waitOnStop {
log.Infof("waiting for interrupt")
select {
case <-l.stopper:
}
}
log.Infof("stopping")
l.mu.Lock()
defer l.mu.Unlock()
if l.monitorCtxCancelFunc != nil {
l.monitorCtxCancelFunc()
l.monitorCtxCancelFunc = nil
}
if l.vols != nil {
maybePanic(l.vols.Kill())
maybePanic(l.vols.Remove())
l.vols = nil
}
if l.CertsDir != "" {
_ = os.RemoveAll(l.CertsDir)
l.CertsDir = ""
}
outputLogDir := l.logDir
for i, n := range l.Nodes {
ci, err := n.Inspect()
crashed := err != nil || (!ci.State.Running && ci.State.ExitCode != 0)
maybePanic(n.Kill())
if crashed && outputLogDir == "" {
outputLogDir = util.CreateTempDir(util.PanicTester, "crashed_nodes")
}
if crashed || l.logDir != "" {
// TODO(bdarnell): make these filenames more consistent with
// structured logs?
file := filepath.Join(outputLogDir, nodeStr(i),
fmt.Sprintf("stderr.%s.log", strings.Replace(
timeutil.Now().Format(time.RFC3339), ":", "_", -1)))
maybePanic(os.MkdirAll(filepath.Dir(file), 0777))
w, err := os.Create(file)
maybePanic(err)
defer w.Close()
maybePanic(n.Logs(w))
if crashed {
log.Infof("node %d: stderr at %s", i, file)
}
}
maybePanic(n.Remove())
}
l.Nodes = nil
if l.networkID != "" {
maybePanic(l.client.NetworkRemove(context.Background(), l.networkID))
l.networkID = ""
}
}
开发者ID:bogdanbatog,项目名称:cockroach,代码行数:61,代码来源:localcluster.go
示例15: BenchmarkMVCCPutDelete_RocksDB
func BenchmarkMVCCPutDelete_RocksDB(b *testing.B) {
const cacheSize = 1 << 30 // 1 GB
rocksdb, stopper := setupMVCCInMemRocksDB(b, "put_delete")
defer stopper.Stop()
r := rand.New(rand.NewSource(int64(timeutil.Now().UnixNano())))
value := roachpb.MakeValueFromBytes(randutil.RandBytes(r, 10))
zeroTS := roachpb.ZeroTimestamp
var blockNum int64
for i := 0; i < b.N; i++ {
blockID := r.Int63()
blockNum++
key := encoding.EncodeVarintAscending(nil, blockID)
key = encoding.EncodeVarintAscending(key, blockNum)
if err := MVCCPut(context.Background(), rocksdb, nil, key, zeroTS, value, nil /* txn */); err != nil {
b.Fatal(err)
}
if err := MVCCDelete(context.Background(), rocksdb, nil, key, zeroTS, nil /* txn */); err != nil {
b.Fatal(err)
}
}
}
开发者ID:chzyer-dev,项目名称:cockroach,代码行数:25,代码来源:bench_test.go
示例16: waitAndProcess
// waitAndProcess waits for the pace interval and processes the replica
// if repl is not nil. The method returns true when the scanner needs
// to be stopped. The method also removes a replica from queues when it
// is signaled via the removed channel.
func (rs *replicaScanner) waitAndProcess(start time.Time, clock *hlc.Clock, stopper *stop.Stopper,
repl *Replica) bool {
waitInterval := rs.paceInterval(start, timeutil.Now())
rs.waitTimer.Reset(waitInterval)
if log.V(6) {
log.Infof("Wait time interval set to %s", waitInterval)
}
for {
select {
case <-rs.waitTimer.C:
rs.waitTimer.Read = true
if repl == nil {
return false
}
return !stopper.RunTask(func() {
// Try adding replica to all queues.
for _, q := range rs.queues {
q.MaybeAdd(repl, clock.Now())
}
})
case repl := <-rs.removed:
// Remove replica from all queues as applicable.
for _, q := range rs.queues {
q.MaybeRemove(repl)
}
if log.V(6) {
log.Infof("removed replica %s", repl)
}
case <-stopper.ShouldStop():
return true
}
}
}
开发者ID:cuongdo,项目名称:cockroach,代码行数:38,代码来源:scanner.go
示例17: String
func (sp *StorePool) String() string {
sp.mu.Lock()
defer sp.mu.Unlock()
ids := make(roachpb.StoreIDSlice, 0, len(sp.mu.stores))
for id := range sp.mu.stores {
ids = append(ids, id)
}
sort.Sort(ids)
var buf bytes.Buffer
now := timeutil.Now()
for _, id := range ids {
detail := sp.mu.stores[id]
fmt.Fprintf(&buf, "%d", id)
if detail.dead {
_, _ = buf.WriteString("*")
}
fmt.Fprintf(&buf, ": range-count=%d fraction-used=%.2f",
detail.desc.Capacity.RangeCount, detail.desc.Capacity.FractionUsed())
throttled := detail.throttledUntil.Sub(now)
if throttled > 0 {
fmt.Fprintf(&buf, " [throttled=%.1fs]", throttled.Seconds())
}
_, _ = buf.WriteString("\n")
}
return buf.String()
}
开发者ID:yangxuanjia,项目名称:cockroach,代码行数:29,代码来源:store_pool.go
示例18: BenchmarkMVCCPutDelete
func BenchmarkMVCCPutDelete(b *testing.B) {
const cacheSize = 1 << 30 // 1 GB
stopper := stop.NewStopper()
rocksdb := NewInMem(roachpb.Attributes{}, cacheSize, stopper)
defer stopper.Stop()
r := rand.New(rand.NewSource(int64(timeutil.Now().UnixNano())))
value := roachpb.MakeValueFromBytes(randutil.RandBytes(r, 10))
zeroTS := roachpb.ZeroTimestamp
var blockNum int64
for i := 0; i < b.N; i++ {
blockID := r.Int63()
blockNum++
key := encoding.EncodeVarintAscending(nil, blockID)
key = encoding.EncodeVarintAscending(key, blockNum)
if err := MVCCPut(rocksdb, nil, key, zeroTS, value, nil /* txn */); err != nil {
b.Fatal(err)
}
if err := MVCCDelete(rocksdb, nil, key, zeroTS, nil /* txn */); err != nil {
b.Fatal(err)
}
}
}
开发者ID:cuongdo,项目名称:cockroach,代码行数:26,代码来源:rocksdb_test.go
示例19: waitAndProcess
// waitAndProcess waits for the pace interval and processes the replica
// if repl is not nil. The method returns true when the scanner needs
// to be stopped. The method also removes a replica from queues when it
// is signaled via the removed channel.
func (rs *replicaScanner) waitAndProcess(
start time.Time, clock *hlc.Clock, stopper *stop.Stopper, repl *Replica,
) bool {
waitInterval := rs.paceInterval(start, timeutil.Now())
rs.waitTimer.Reset(waitInterval)
if log.V(6) {
log.Infof(context.TODO(), "wait timer interval set to %s", waitInterval)
}
for {
select {
case <-rs.waitTimer.C:
if log.V(6) {
log.Infof(context.TODO(), "wait timer fired")
}
rs.waitTimer.Read = true
if repl == nil {
return false
}
return nil != stopper.RunTask(func() {
// Try adding replica to all queues.
for _, q := range rs.queues {
q.MaybeAdd(repl, clock.Now())
}
})
case repl := <-rs.removed:
rs.removeReplica(repl)
case <-stopper.ShouldStop():
return true
}
}
}
开发者ID:yaojingguo,项目名称:cockroach,代码行数:38,代码来源:scanner.go
示例20: generateUniqueBytes
func generateUniqueBytes(nodeID roachpb.NodeID) DBytes {
// Unique bytes are composed of the current time in nanoseconds and the
// node-id. If the nanosecond value is the same on two consecutive calls to
// timeutil.Now() the nanoseconds value is incremented. The node-id is varint
// encoded. Since node-ids are allocated consecutively starting at 1, the
// node-id field will consume 1 or 2 bytes for any reasonably sized cluster.
//
// TODO(pmattis): Do we have to worry about persisting the milliseconds value
// periodically to avoid the clock ever going backwards (e.g. due to NTP
// adjustment)?
nanos := uint64(timeutil.Now().UnixNano())
uniqueBytesState.Lock()
if nanos <= uniqueBytesState.nanos {
nanos = uniqueBytesState.nanos + 1
}
uniqueBytesState.nanos = nanos
uniqueBytesState.Unlock()
b := make([]byte, 0, 8+binary.MaxVarintLen32)
b = encoding.EncodeUint64Ascending(b, nanos)
// We use binary.PutUvarint instead of encoding.EncodeUvarint because the
// former uses less space for values < 128 which is a common occurrence for
// node IDs.
n := binary.PutUvarint(b[len(b):len(b)+binary.MaxVarintLen32], uint64(nodeID))
return DBytes(b[:len(b)+n])
}
开发者ID:cuongdo,项目名称:cockroach,代码行数:26,代码来源:builtins.go
注:本文中的github.com/cockroachdb/cockroach/util/timeutil.Now函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论