func (txio *DBTransactionLogIO) Sync() error {
	txio.mu.Lock()
	batch := txio.nextbatch
	txio.nextbatch = make([]inodedb.DBTransaction, 0)
	txio.mu.Unlock()

	if len(batch) == 0 {
		return nil
	}

	ctx := txio.getContext()
	keys := make([]*datastore.Key, 0, len(batch))
	stxs := make([]*storedbtx, 0, len(batch))
	for _, tx := range batch {
		keys = append(keys, datastore.NewKey(ctx, kindTransaction, "", int64(tx.TxID), txio.rootKey))
		stx, err := encode(txio.c, tx)
		if err != nil {
			return err
		}
		stxs = append(stxs, stx)
	}

	if _, err := datastore.PutMulti(ctx, keys, stxs); err != nil {
		return err
	}
	log.Printf("Committed %d txs", len(stxs))
	return nil
}
Beispiel #2
0
func (ds *Datastore) Commit(t string, its []*x.Instruction) error {
	var keys []*datastore.Key
	for _, i := range its {
		dkey := ds.getIKey(*i, t)
		keys = append(keys, dkey)
	}
	if _, err := datastore.PutMulti(ds.ctx, keys, its); err != nil {
		x.LogErr(log, err).Error("While committing instructions")
		return err
	}
	log.Debugf("%d Instructions committed", len(its))
	return nil
}
Beispiel #3
0
func ExamplePutMulti_interfaceSlice() {
	ctx := Example_auth()

	keys := []*datastore.Key{
		datastore.NewKey(ctx, "Post", "post1", 0, nil),
		datastore.NewKey(ctx, "Post", "post2", 0, nil),
	}

	// PutMulti with an empty interface slice.
	posts := []interface{}{
		&Post{Title: "Post 1", PublishedAt: time.Now()},
		&Post{Title: "Post 2", PublishedAt: time.Now()},
	}
	if _, err := datastore.PutMulti(ctx, keys, posts); err != nil {
		log.Fatal(err)
	}
}