Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ai3
tools
tabacco
Commits
e977bcbb
Commit
e977bcbb
authored
Aug 03, 2018
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix error in FindRequest.NumVersions handling
parent
61866cab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
10 deletions
+23
-10
metadb/server/service.go
metadb/server/service.go
+21
-9
metadb/server/service_test.go
metadb/server/service_test.go
+2
-1
No files found.
metadb/server/service.go
View file @
e977bcbb
...
...
@@ -3,6 +3,7 @@ package server
import
(
"context"
"database/sql"
"fmt"
"log"
"path/filepath"
"strings"
...
...
@@ -64,6 +65,11 @@ func (a *dbAtom) getAtom() tabacco.Atom {
}
func
normalizeAtoms
(
dbAtoms
[]
dbAtom
,
numVersions
int
)
[][]
tabacco
.
Version
{
// numVersions == 0 is remapped to 1.
if
numVersions
<
1
{
numVersions
=
1
}
// Accumulate versions keyed by backup ID first, dataset name
// next. Preserve the ordering of backups in dbAtoms, which we
// are going to use later to apply a per-dataset limit.
...
...
@@ -104,11 +110,10 @@ func normalizeAtoms(dbAtoms []dbAtom, numVersions int) [][]tabacco.Version {
backup
:=
backupMap
[
backupID
]
var
tmpv
[]
tabacco
.
Version
for
_
,
ds
:=
range
tmp
{
if
dsCount
[
ds
.
Name
]
>=
numVersions
{
continue
if
dsCount
[
ds
.
Name
]
<
numVersions
{
tmpv
=
append
(
tmpv
,
tabacco
.
Version
{
Backup
:
*
backup
,
Dataset
:
*
ds
})
dsCount
[
ds
.
Name
]
++
}
tmpv
=
append
(
tmpv
,
tabacco
.
Version
{
Backup
:
*
backup
,
Dataset
:
*
ds
})
dsCount
[
ds
.
Name
]
++
}
if
len
(
tmpv
)
>
0
{
out
=
append
(
out
,
tmpv
)
...
...
@@ -193,6 +198,8 @@ func (s *Service) FindAtoms(ctx context.Context, req tabacco.FindRequest) ([][]t
}
defer
tx
.
Rollback
()
// nolint
// Build the SQL query. Assemble the WHERE clauses and their
// respective arguments first.
var
where
[]
string
var
args
[]
interface
{}
if
req
.
Host
!=
""
{
...
...
@@ -204,11 +211,16 @@ func (s *Service) FindAtoms(ctx context.Context, req tabacco.FindRequest) ([][]t
args
=
append
(
args
,
strings
.
Replace
(
req
.
Pattern
,
"*"
,
"%"
,
-
1
))
}
q
:=
` SELECT
backup_id, backup_timestamp, backup_host,
dataset_name, dataset_handler,
atom_name, atom_path, atom_source_path, atom_relative_path
FROM log WHERE `
+
strings
.
Join
(
where
,
" AND "
)
// Build the final query and execute it.
q
:=
fmt
.
Sprintf
(
`SELECT
backup_id, backup_timestamp, backup_host,
dataset_name, dataset_handler,
atom_name, atom_path, atom_source_path, atom_relative_path
FROM log WHERE %s
ORDER BY backup_timestamp DESC`
,
strings
.
Join
(
where
,
" AND "
),
)
rows
,
err
:=
tx
.
Query
(
q
,
args
...
)
if
err
!=
nil
{
return
nil
,
err
...
...
metadb/server/service_test.go
View file @
e977bcbb
...
...
@@ -69,7 +69,8 @@ func TestService_FindAtoms(t *testing.T) {
vv
,
err
:=
svc
.
FindAtoms
(
context
.
Background
(),
tabacco
.
FindRequest
{
Pattern
:
"*/sub1"
,
Pattern
:
"*/sub1"
,
NumVersions
:
10
,
},
)
if
err
!=
nil
{
...
...
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