Git Product home page Git Product logo

Comments (5)

rekby avatar rekby commented on August 26, 2024 1

как тебе вариант сначала создавать локер (без серверного вызова), а потом блокировки дёргать уже через него?
контекст при возврате тогда точно не нужен, ошибка тут опциональна - тольпо для проверки аргумента ресурса.

locker := db.Coordination().CreateLocker("resource")
ctx, err := locker.Lock(ctx)
...
locker.Unlock(ctx)


ctx, err := locker.Lock(ctx, WithLockCount(3))
...
locker.Unlock(ctx, WithLockCount(2)) // тут как я понял надо дать возможность частичной разблокировки.
// если разблокировать можно только тот вес, что взял - при анлоке эту опцию просто не допускать.

from ydb-go-sdk.

asmyasnikov avatar asmyasnikov commented on August 26, 2024
// wait for lock
// Returned ctx with cancel, 
// use it for operations under lock
locker, ctx, err := db.Coordination().Lock(
  ctx, 
  "resource", 
  coordination.WithCount(2),
)
If err != nil {
  // wrap err
}
defer locker.Unlock(
  coordination.WitchCount(2),
)
// Doing under lock

from ydb-go-sdk.

floatdrop avatar floatdrop commented on August 26, 2024

Here one use case from the wild. We need to launch migrations in global (in scope of database) lock to eliminate concurrent database modification: golang-migrate/migrate#677 (comment)

from ydb-go-sdk.

asmyasnikov avatar asmyasnikov commented on August 26, 2024

Наверное так можно будет разделить блокировки. Есть ещё нюанс - ресурс надо создавать с одинаковым счётчиком на всех клиентах. Если первый клиент ждёт локер на 10, а второй на 100, то надо возвратить где-то ошибку

from ydb-go-sdk.

rekby avatar rekby commented on August 26, 2024

Если счётчик всегда одинаковый - зачем он вообще нужен? тогда получается это просто shared-lock с ограничением на количество локов и параметр не нужен.

from ydb-go-sdk.

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.