-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
'sdk-ify' the distribute lock implementations
Signed-off-by: Alexandre Lamarre <alex7285@gmail.com>
- Loading branch information
1 parent
66a223b
commit b6b3a8e
Showing
5 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# These are supported funding model platforms | ||
|
||
github: [alexandreLamarre] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package etcd | ||
|
||
import ( | ||
"log/slog" | ||
|
||
"github.com/alexandreLamarre/dlock/internal/lock/backend/etcd" | ||
"github.com/alexandreLamarre/dlock/pkg/lock" | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
func NewLock( | ||
lg *slog.Logger, | ||
client *clientv3.Client, | ||
prefix, key string, | ||
options *lock.LockOptions, | ||
) lock.Lock { | ||
return etcd.NewEtcdLock(lg, client, prefix, key, options) | ||
} | ||
|
||
func NewLockManager( | ||
lg *slog.Logger, | ||
client *clientv3.Client, | ||
prefix string, | ||
tracer trace.Tracer, | ||
) lock.LockManager { | ||
return etcd.NewEtcdLockManager(client, prefix, tracer, lg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package jetstream | ||
|
||
import ( | ||
"context" | ||
"log/slog" | ||
|
||
"github.com/alexandreLamarre/dlock/internal/lock/backend/jetstream" | ||
"github.com/alexandreLamarre/dlock/pkg/lock" | ||
"github.com/nats-io/nats.go" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
func NewLock( | ||
lg *slog.Logger, | ||
js nats.JetStreamContext, | ||
prefix, key string, | ||
options *lock.LockOptions, | ||
) lock.Lock { | ||
return jetstream.NewLock(js, prefix, key, lg, options) | ||
} | ||
|
||
func NewLockManager( | ||
ctx context.Context, | ||
lg *slog.Logger, | ||
js nats.JetStreamContext, | ||
prefix string, | ||
tracer trace.Tracer, | ||
) lock.LockManager { | ||
return jetstream.NewLockManager(ctx, js, prefix, tracer, lg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package redis | ||
|
||
import ( | ||
"context" | ||
"log/slog" | ||
|
||
rl "github.com/alexandreLamarre/dlock/internal/lock/backend/redis" | ||
"github.com/alexandreLamarre/dlock/pkg/lock" | ||
"github.com/go-redsync/redsync/v4/redis" | ||
) | ||
|
||
func NewLock( | ||
pools []redis.Pool, | ||
quorum int, | ||
prefix, key string, | ||
lg *slog.Logger, | ||
opts *lock.LockOptions, | ||
) lock.Lock { | ||
return rl.NewLock( | ||
pools, | ||
quorum, | ||
prefix, | ||
key, | ||
lg, | ||
opts, | ||
) | ||
} | ||
|
||
func NewLockManager( | ||
ctx context.Context, | ||
prefix string, | ||
pools []redis.Pool, | ||
lg *slog.Logger, | ||
) lock.LockManager { | ||
return rl.NewLockManager( | ||
ctx, | ||
prefix, | ||
pools, | ||
lg, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Provides an SDK for embedding distributed lock mechanisms without the need to run a dedicated server. | ||
|
||
// **Note:** It is recommended to use the server binary for production environments, as it | ||
// is guaranteed to handle synchronization edge cases that may not be fully addressed when using the plain SDK. | ||
package sdk |