Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
ea4f3fd3
Commit
ea4f3fd3
authored
Oct 04, 2016
by
Eric Chiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage/sql: enable garbage collection
Was an oversite of the initial SQL PR.
parent
ea3a4293
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
5 deletions
+43
-5
config.go
storage/sql/config.go
+11
-2
gc.go
storage/sql/gc.go
+32
-3
No files found.
storage/sql/config.go
View file @
ea4f3fd3
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"fmt"
"fmt"
"net/url"
"net/url"
"strconv"
"strconv"
"time"
"github.com/coreos/dex/storage"
"github.com/coreos/dex/storage"
)
)
...
@@ -17,7 +18,11 @@ type SQLite3 struct {
...
@@ -17,7 +18,11 @@ type SQLite3 struct {
// Open creates a new storage implementation backed by SQLite3
// Open creates a new storage implementation backed by SQLite3
func
(
s
*
SQLite3
)
Open
()
(
storage
.
Storage
,
error
)
{
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
)
{
func
(
s
*
SQLite3
)
open
()
(
*
conn
,
error
)
{
...
@@ -67,7 +72,11 @@ type Postgres struct {
...
@@ -67,7 +72,11 @@ type Postgres struct {
// Open creates a new storage implementation backed by Postgres.
// Open creates a new storage implementation backed by Postgres.
func
(
p
*
Postgres
)
Open
()
(
storage
.
Storage
,
error
)
{
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
)
{
func
(
p
*
Postgres
)
open
()
(
*
conn
,
error
)
{
...
...
storage/sql/gc.go
View file @
ea4f3fd3
package
sql
package
sql
import
(
import
(
"context"
"fmt"
"fmt"
"log"
"time"
"time"
"github.com/coreos/dex/storage"
)
)
type
gc
struct
{
type
gc
struct
{
...
@@ -10,10 +14,8 @@ type gc struct {
...
@@ -10,10 +14,8 @@ type gc struct {
conn
*
conn
conn
*
conn
}
}
var
tablesWithGC
=
[]
string
{
"auth_request"
,
"auth_code"
}
func
(
gc
gc
)
run
()
error
{
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
())
_
,
err
:=
gc
.
conn
.
Exec
(
`delete from `
+
table
+
` where expiry < $1`
,
gc
.
now
())
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"gc %s: %v"
,
table
,
err
)
return
fmt
.
Errorf
(
"gc %s: %v"
,
table
,
err
)
...
@@ -22,3 +24,30 @@ func (gc gc) run() error {
...
@@ -22,3 +24,30 @@ func (gc gc) run() error {
}
}
return
nil
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
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment