-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Use global lock instead of NewExclusivePool to allow distributed lock between multiple Gitea instances #31813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1c483f8
Use an abstract lock layer to allow distributed lock between multiple…
lunny b98fb46
Merge branch 'main' into lunny/lock_abstract2
lunny 5141395
Fix go tidy
lunny b0f6710
Revert changes about status table
lunny 1748ba8
Revert unnecessary change
lunny 0c3c1a3
refactor the names and add remove locker
lunny 3d3bfaa
Merge branch 'main' into lunny/lock_abstract2
lunny 1276449
Merge branch 'main' into lunny/lock_abstract2
lunny 35daece
use globallock lock
lunny fe9efa9
finish the global lock init
lunny 4bf86e9
Follow the old logic
lunny 1e1d6e9
Use lockCtx when necessary
lunny 3e268b9
Merge branch 'main' into lunny/lock_abstract2
lunny 8e09e01
Use correct ctx usage
lunny 30dc681
Merge branch 'main' into lunny/lock_abstract2
lunny 860f3ec
Follow global lock refactor
lunny aa51a8c
fix: always defer release
wolfogre 5df67a8
Merge branch 'main' into lunny/lock_abstract2
lafriks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,37 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package setting | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/nosql" | ||
) | ||
|
||
// GlobalLock represents configuration of global lock | ||
var GlobalLock = struct { | ||
ServiceType string | ||
ServiceConnStr string | ||
}{ | ||
ServiceType: "memory", | ||
} | ||
|
||
func loadGlobalLockFrom(rootCfg ConfigProvider) { | ||
sec := rootCfg.Section("global_lock") | ||
GlobalLock.ServiceType = sec.Key("SERVICE_TYPE").MustString("memory") | ||
switch GlobalLock.ServiceType { | ||
case "memory": | ||
case "redis": | ||
connStr := sec.Key("SERVICE_CONN_STR").String() | ||
if connStr == "" { | ||
log.Fatal("SERVICE_CONN_STR is empty for redis") | ||
} | ||
u := nosql.ToRedisURI(connStr) | ||
if u == nil { | ||
log.Fatal("SERVICE_CONN_STR %s is not a valid redis connection string", connStr) | ||
} | ||
GlobalLock.ServiceConnStr = connStr | ||
default: | ||
log.Fatal("Unknown sync lock service type: %s", GlobalLock.ServiceType) | ||
} | ||
} |
This file contains hidden or 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,35 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package setting | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLoadGlobalLockConfig(t *testing.T) { | ||
t.Run("DefaultGlobalLockConfig", func(t *testing.T) { | ||
iniStr := `` | ||
cfg, err := NewConfigProviderFromData(iniStr) | ||
assert.NoError(t, err) | ||
|
||
loadGlobalLockFrom(cfg) | ||
assert.EqualValues(t, "memory", GlobalLock.ServiceType) | ||
}) | ||
|
||
t.Run("RedisGlobalLockConfig", func(t *testing.T) { | ||
iniStr := ` | ||
[global_lock] | ||
SERVICE_TYPE = redis | ||
SERVICE_CONN_STR = addrs=127.0.0.1:6379 db=0 | ||
` | ||
cfg, err := NewConfigProviderFromData(iniStr) | ||
assert.NoError(t, err) | ||
|
||
loadGlobalLockFrom(cfg) | ||
assert.EqualValues(t, "redis", GlobalLock.ServiceType) | ||
assert.EqualValues(t, "addrs=127.0.0.1:6379 db=0", GlobalLock.ServiceConnStr) | ||
}) | ||
} |
This file contains hidden or 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
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.