Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
dex
Commits
3681a57a
Commit
3681a57a
authored
Oct 4, 2016
by
Eric Chiang
Committed by
GitHub
Oct 4, 2016
Browse files
Options
Downloads
Plain Diff
Merge pull request #587 from ericchiang/dev-sql-enable-gc
storage/sql: enable garbage collection
parents
ea3a4293
ea4f3fd3
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
storage/sql/config.go
+11
-2
11 additions, 2 deletions
storage/sql/config.go
storage/sql/gc.go
+32
-3
32 additions, 3 deletions
storage/sql/gc.go
with
43 additions
and
5 deletions
storage/sql/config.go
+
11
−
2
View file @
3681a57a
...
...
@@ -5,6 +5,7 @@ import (
"fmt"
"net/url"
"strconv"
"time"
"github.com/coreos/dex/storage"
)
...
...
@@ -17,7 +18,11 @@ type SQLite3 struct {
// Open creates a new storage implementation backed by SQLite3
func
(
s
*
SQLite3
)
Open
()
(
storage
.
Storage
,
error
)
{
return
s
.
open
()
conn
,
err
:=
s
.
open
()
if
err
!=
nil
{
return
nil
,
err
}
return
withGC
(
conn
,
time
.
Now
),
nil
}
func
(
s
*
SQLite3
)
open
()
(
*
conn
,
error
)
{
...
...
@@ -67,7 +72,11 @@ type Postgres struct {
// Open creates a new storage implementation backed by Postgres.
func
(
p
*
Postgres
)
Open
()
(
storage
.
Storage
,
error
)
{
return
p
.
open
()
conn
,
err
:=
p
.
open
()
if
err
!=
nil
{
return
nil
,
err
}
return
withGC
(
conn
,
time
.
Now
),
nil
}
func
(
p
*
Postgres
)
open
()
(
*
conn
,
error
)
{
...
...
This diff is collapsed.
Click to expand it.
storage/sql/gc.go
+
32
−
3
View file @
3681a57a
package
sql
import
(
"context"
"fmt"
"log"
"time"
"github.com/coreos/dex/storage"
)
type
gc
struct
{
...
...
@@ -10,10 +14,8 @@ type gc struct {
conn
*
conn
}
var
tablesWithGC
=
[]
string
{
"auth_request"
,
"auth_code"
}
func
(
gc
gc
)
run
()
error
{
for
_
,
table
:=
range
tablesWithGC
{
for
_
,
table
:=
range
[]
string
{
"auth_request"
,
"auth_code"
}
{
_
,
err
:=
gc
.
conn
.
Exec
(
`delete from `
+
table
+
` where expiry < $1`
,
gc
.
now
())
if
err
!=
nil
{
return
fmt
.
Errorf
(
"gc %s: %v"
,
table
,
err
)
...
...
@@ -22,3 +24,30 @@ func (gc gc) run() error {
}
return
nil
}
type
withCancel
struct
{
storage
.
Storage
cancel
context
.
CancelFunc
}
func
(
w
withCancel
)
Close
()
error
{
w
.
cancel
()
return
w
.
Storage
.
Close
()
}
func
withGC
(
conn
*
conn
,
now
func
()
time
.
Time
)
storage
.
Storage
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
run
:=
(
gc
{
now
,
conn
})
.
run
go
func
()
{
for
{
select
{
case
<-
time
.
After
(
time
.
Second
*
30
)
:
if
err
:=
run
();
err
!=
nil
{
log
.
Printf
(
"gc failed: %v"
,
err
)
}
case
<-
ctx
.
Done
()
:
}
}
}()
return
withCancel
{
conn
,
cancel
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment