- Notifications
You must be signed in to change notification settings - Fork928
feat: use JWT ticket to avoid DB queries on apps#6148
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
cd239fa
24d1112
8ffd8d4
a392635
e60c645
e681f4c
16cf790
22707c6
3521669
bffd775
b8a5526
e0e4237
f236a14
189eecf
df6a9e5
9c40076
f16609f
45f38bc
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -64,6 +64,7 @@ func New() database.Store { | ||
workspaceApps: make([]database.WorkspaceApp, 0), | ||
workspaces: make([]database.Workspace, 0), | ||
licenses: make([]database.License, 0), | ||
locks: map[int64]struct{}{}, | ||
}, | ||
} | ||
} | ||
@@ -89,6 +90,11 @@ type fakeQuerier struct { | ||
*data | ||
} | ||
type fakeTx struct { | ||
*fakeQuerier | ||
locks map[int64]struct{} | ||
} | ||
type data struct { | ||
// Legacy tables | ||
apiKeys []database.APIKey | ||
@@ -124,11 +130,15 @@ type data struct { | ||
workspaceResources []database.WorkspaceResource | ||
workspaces []database.Workspace | ||
// Locks is a map of lock names. Any keys within the map are currently | ||
// locked. | ||
locks map[int64]struct{} | ||
deploymentID string | ||
derpMeshKey string | ||
lastUpdateCheck []byte | ||
serviceBanner []byte | ||
logoURL string | ||
appSigningKey string | ||
lastLicenseID int32 | ||
} | ||
@@ -196,11 +206,50 @@ func (*fakeQuerier) Ping(_ context.Context) (time.Duration, error) { | ||
return 0, nil | ||
} | ||
func (*fakeQuerier) AcquireLock(_ context.Context, _ int64) error { | ||
return xerrors.New("AcquireLock must only be called within a transaction") | ||
} | ||
func (*fakeQuerier) TryAcquireLock(_ context.Context, _ int64) (bool, error) { | ||
return false, xerrors.New("TryAcquireLock must only be called within a transaction") | ||
} | ||
func (tx *fakeTx) AcquireLock(_ context.Context, id int64) error { | ||
if _, ok := tx.fakeQuerier.locks[id]; ok { | ||
return xerrors.Errorf("cannot acquire lock %d: already held", id) | ||
} | ||
tx.fakeQuerier.locks[id] = struct{}{} | ||
tx.locks[id] = struct{}{} | ||
return nil | ||
} | ||
func (tx *fakeTx) TryAcquireLock(_ context.Context, id int64) (bool, error) { | ||
if _, ok := tx.fakeQuerier.locks[id]; ok { | ||
return false, nil | ||
} | ||
tx.fakeQuerier.locks[id] = struct{}{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Should this be protected or use sync.Map? Otherwise we may have concurrent map read/writes between goroutines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I wouldn't expect a transaction to be used concurrently from two places at once (and I don't think that even works anyways) but I can add this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. For example, the lock on the underlying data struct is replaced with a noop lock in a tx, so concurrent database read/writes may panic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I've actually decided against this for the above reason. | ||
tx.locks[id] = struct{}{} | ||
return true, nil | ||
} | ||
func (tx *fakeTx) releaseLocks() { | ||
for id := range tx.locks { | ||
delete(tx.fakeQuerier.locks, id) | ||
} | ||
tx.locks = map[int64]struct{}{} | ||
} | ||
// InTx doesn't rollback data properly for in-memory yet. | ||
func (q *fakeQuerier) InTx(fn func(database.Store) error, _ *sql.TxOptions) error { | ||
q.mutex.Lock() | ||
defer q.mutex.Unlock() | ||
tx := &fakeTx{ | ||
fakeQuerier: &fakeQuerier{mutex: inTxMutex{}, data: q.data}, | ||
locks: map[int64]struct{}{}, | ||
} | ||
defer tx.releaseLocks() | ||
return fn(tx) | ||
} | ||
func (q *fakeQuerier) AcquireProvisionerJob(_ context.Context, arg database.AcquireProvisionerJobParams) (database.ProvisionerJob, error) { | ||
@@ -4004,6 +4053,21 @@ func (q *fakeQuerier) GetLogoURL(_ context.Context) (string, error) { | ||
return q.logoURL, nil | ||
} | ||
func (q *fakeQuerier) GetAppSigningKey(_ context.Context) (string, error) { | ||
q.mutex.RLock() | ||
defer q.mutex.RUnlock() | ||
return q.appSigningKey, nil | ||
} | ||
func (q *fakeQuerier) InsertAppSigningKey(_ context.Context, data string) error { | ||
q.mutex.Lock() | ||
defer q.mutex.Unlock() | ||
q.appSigningKey = data | ||
return nil | ||
} | ||
func (q *fakeQuerier) InsertLicense( | ||
_ context.Context, arg database.InsertLicenseParams, | ||
) (database.License, error) { | ||
Uh oh!
There was an error while loading.Please reload this page.