Giter Site home page Giter Site logo

Batch operations about gokv HOT 3 OPEN

simar7 avatar simar7 commented on June 14, 2024
Batch operations

from gokv.

Comments (3)

simar7 avatar simar7 commented on June 14, 2024 1

Hey! Yes I meant to say that the bbolt batch method could call the underlying bbolt batch method as I had linked earlier.

Not all of the databases that have a gokv.Store implementation support batch operations natively. For other DBs you could implement a convenience method that then calls the single Set method multiple times for all elements of the slice, but then what about databases that don't support transactions? You could ignore transactions and just call Set multiple times, but the method caller (package user) might expect an atomic transaction for each SetBatch call.

Yes precisely this. Where it makes sense, the implementation will call the batch operation for that datastore. Where it doesn't, we could invoke Set multiple times, or better and more safer, not have it implemented and leave the decision on the user to decide if they wanted to implement it themselves (by wrapping regular Set in a loop, interface embedding and extending it, etc.)

from gokv.

philippgille avatar philippgille commented on June 14, 2024

Hi! Sorry for the late reply!

Do you mean something exactly like the bbolt Batch method you linked to, where the docs say:

Batch is only useful when there are multiple goroutines calling it.

Or do you mean batch methods in general, where you can set/delete multiple values within a single transaction, so the required gokv.Store method would looke something like SetBatch(key string, values ...interface{}) error (with values being variadic) or similar?

Method signature options could then be (for this latter understanding of what you mean with batch):

package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello, playground")

	key := "k"

	setBatch1(key, 1, "2")

	vals := make([]interface{}, 2)
	vals[0] = 1
	vals[1] = "2"

	setBatch2(key, vals)

	setBatch3(key, vals)
}

func setBatch1(key string, values ...interface{}) {
	fmt.Printf("values[0]: %v (%T); values[1]: %v (%T)\n", values[0], values[0], values[1], values[1])
}

func setBatch2(key string, values []interface{}) {
	fmt.Printf("values[0]: %v (%T); values[1]: %v (%T)\n", values[0], values[0], values[1], values[1])
}

func setBatch3(key string, values interface{}) {
	vals, ok := values.([]interface{})
	if !ok {
		panic("nok")
	}
	fmt.Printf("values[0]: %v (%T); values[1]: %v (%T)\n", vals[0], vals[0], vals[1], vals[1])
}

(https://play.golang.org/p/HlOR1I6P81f)

But:

Not all of the databases that have a gokv.Store implementation support batch operations natively. For other DBs you could implement a convenience method that then calls the single Set method multiple times for all elements of the slice, but then what about databases that don't support transactions? You could ignore transactions and just call Set multiple times, but the method caller (package user) might expect an atomic transaction for each SetBatch call.

What do you think?

from gokv.

glimchb avatar glimchb commented on June 14, 2024

for atomicity, we can take a mutex... and then call loop of sets... no ?
obviously, only applicable if called from the same app...

from gokv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.