Comments (5)
как тебе вариант сначала создавать локер (без серверного вызова), а потом блокировки дёргать уже через него?
контекст при возврате тогда точно не нужен, ошибка тут опциональна - тольпо для проверки аргумента ресурса.
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.
// 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.
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.
Наверное так можно будет разделить блокировки. Есть ещё нюанс - ресурс надо создавать с одинаковым счётчиком на всех клиентах. Если первый клиент ждёт локер на 10, а второй на 100, то надо возвратить где-то ошибку
from ydb-go-sdk.
Если счётчик всегда одинаковый - зачем он вообще нужен? тогда получается это просто shared-lock с ограничением на количество локов и параметр не нужен.
from ydb-go-sdk.
Related Issues (20)
- bug: Need stop topic writer WaitInit on schema error
- Go: Operation service client
- feat: Commit messages from topic with transaction
- bug: Session leak on Table().Do()
- bug: Reading rows from the second `ResultSet` leads to unexpected error instead of `io.EOF` HOT 1
- bug: `Query().Do` doesn't up/insert when calling `Execute(...)` with `SerializableReadWriteTxControl()` HOT 1
- feat: metrics over table
- bug: Infinite reconnection on TLS error
- feat: optimize topic message reader usage
- bug: wrap initialization error as operation status error - for handle with retrier
- bug: panic on createSession when returned nil session HOT 2
- bug: Real error from session pool is hidden by DeadlineExceeded from retrier.
- Need to update configs to last version of golangci-lint (v1.59.1)
- bug: `ydb.Open` trace goes infinitely HOT 1
- feat: split `query.Result` tracing details into Result, ResultSet and Row with scan spans
- bug: `query.ExecModeExplain` returns `io.EOF` when scanning a row
- dev: Remove `io.EOF` and grpc stream context cancellation from `WARN` log level
- feat: remove discovery events properly
- bug: panic on `*Session.Begin` in `safe.ID()` HOT 2
- dev: isolation issue from `v3.77.0`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ydb-go-sdk.