-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix server lock up in high load scenarios
- Loading branch information
Showing
17 changed files
with
495 additions
and
253 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,27 @@ | ||
name: Run integration tests | ||
|
||
on: [ push ] | ||
|
||
env: | ||
GO_VERSION: 1.21.6 | ||
|
||
jobs: | ||
integration-tests: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Build | ||
run: go build -v ./... | ||
- name: Run integration tests | ||
run: go test -json ./test/integration > IntegrationTestResults-${{ env.GO_VERSION }}.json | ||
- name: Upload Go integration tests results | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: Go-results-${{ env.GO_VERSION }} | ||
path: IntegrationTestResults-${{ env.GO_VERSION }}.json |
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
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
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,72 @@ | ||
package lock | ||
|
||
import ( | ||
"context" | ||
"github.com/nitwhiz/omnilock/pkg/util" | ||
"sync" | ||
"time" | ||
) | ||
|
||
type Table struct { | ||
locks *util.Map[string, uint64] | ||
} | ||
|
||
func NewTable() *Table { | ||
return &Table{ | ||
locks: util.NewMap[string, uint64](), | ||
} | ||
} | ||
|
||
func (t *Table) TryLock(name string, clientId uint64) bool { | ||
return t.locks.TryPut(name, clientId) | ||
} | ||
|
||
func (t *Table) Lock(ctx context.Context, name string, clientId uint64) bool { | ||
if t.TryLock(name, clientId) { | ||
return true | ||
} | ||
|
||
result := false | ||
|
||
wg := &sync.WaitGroup{} | ||
isRunning := false | ||
|
||
go func() { | ||
wg.Add(1) | ||
defer wg.Done() | ||
|
||
isRunning = true | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case <-time.After(time.Microsecond * 250): | ||
if t.TryLock(name, clientId) { | ||
result = true | ||
return | ||
} | ||
|
||
break | ||
} | ||
} | ||
}() | ||
|
||
for !isRunning { | ||
<-time.After(time.Millisecond) | ||
} | ||
|
||
wg.Wait() | ||
|
||
return result | ||
} | ||
|
||
func (t *Table) Unlock(name string, clientId uint64) bool { | ||
return t.locks.RemoveIf(name, func(v uint64) bool { | ||
return clientId == v | ||
}) | ||
} | ||
|
||
func (t *Table) UnlockAll(clientId uint64) { | ||
t.locks.RemoveByValue(clientId) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.