Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
asapo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joao Alvim Oliveira Dias De Almeida
asapo
Commits
d09702d0
Commit
d09702d0
authored
1 year ago
by
Mikhail Karnevskiy
Browse files
Options
Downloads
Patches
Plain Diff
Fix acknowledgement for get next available. In-process table now contain only _id, but not time_id.
parent
82672ffc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
broker/src/asapo_broker/database/mongodb.go
+35
-8
35 additions, 8 deletions
broker/src/asapo_broker/database/mongodb.go
with
35 additions
and
8 deletions
broker/src/asapo_broker/database/mongodb.go
+
35
−
8
View file @
d09702d0
...
...
@@ -223,7 +223,7 @@ func maxIndexQuery(request Request, returnIncompete bool) bson.M {
return
q
}
func
getIntVal
(
request
Request
,
val
interface
{})
(
int32
,
error
)
{
func
getInt
32
Val
(
request
Request
,
val
interface
{})
(
int32
,
error
)
{
var
result
int32
switch
v
:=
val
.
(
type
)
{
default
:
...
...
@@ -238,6 +238,21 @@ func getIntVal(request Request, val interface{}) (int32, error) {
return
result
,
nil
}
func
getIntVal
(
request
Request
,
val
interface
{})
(
int
,
error
)
{
var
result
int
switch
v
:=
val
.
(
type
)
{
default
:
request
.
Logger
()
.
Debug
(
"unexpected type %T"
,
v
)
return
0
,
errors
.
New
(
"cannot convert value to int"
)
case
int32
:
result
,
_
=
val
.
(
int
)
case
int64
:
val
,
_
:=
val
.
(
int64
)
result
=
int
(
val
)
}
return
result
,
nil
}
func
(
db
*
Mongodb
)
getMaxIndex
(
request
Request
,
returnIncompete
bool
,
idKey
string
)
(
int
,
error
)
{
c
:=
db
.
client
.
Database
(
request
.
DbName
())
.
Collection
(
data_collection_name_prefix
+
request
.
Stream
)
q
:=
maxIndexQuery
(
request
,
returnIncompete
)
...
...
@@ -251,7 +266,7 @@ func (db *Mongodb) getMaxIndex(request Request, returnIncompete bool, idKey stri
if
err
!=
nil
{
return
0
,
err
}
maxId
,
ok
:=
getIntVal
(
request
,
result
[
idKey
])
maxId
,
ok
:=
getInt
32
Val
(
request
,
result
[
idKey
])
if
ok
!=
nil
{
return
0
,
errors
.
New
(
"cannot get max index by "
+
idKey
)
}
...
...
@@ -667,6 +682,7 @@ func (db *Mongodb) updateCurrentPointerIfEqualDB(request Request, currentValue,
}
// Return record based on current pointer, index of the record and error
// Return actual value of _id, even if request is done for time_id
// If obtaining current pointer fails, record is corrupted or thisis end of stream: return 0 instead of record id
// If record is missing, or incomplete return valid record id
func
(
db
*
Mongodb
)
getRecordFromCurPointer
(
request
Request
,
params
ExtraParamNext
)
([]
byte
,
int
,
error
)
{
...
...
@@ -677,6 +693,13 @@ func (db *Mongodb) getRecordFromCurPointer(request Request, params ExtraParamNex
}
var
res
map
[
string
]
interface
{}
res
,
err
=
db
.
getRecordFromDb
(
request
,
nextInd
,
maxInd
,
params
.
IdKey
)
var
idx
int
if
params
.
IdKey
==
"_id"
{
idx
=
nextInd
}
if
err
==
nil
&&
params
.
IdKey
==
"time_id"
{
idx
,
_
=
getIntVal
(
request
,
res
[
"_id"
])
}
// Missing Id! Since time_Ids are sequential, jump to the next available id
// Update current pointer to next available id
if
err
!=
nil
&&
params
.
IdKey
==
"time_id"
{
...
...
@@ -689,9 +712,13 @@ func (db *Mongodb) getRecordFromCurPointer(request Request, params ExtraParamNex
if
err
!=
nil
{
return
nil
,
0
,
err
}
nextValue
,
ok
:=
getIntVal
(
request
,
res
[
"time_id"
])
nextValue
,
ok
:=
getInt32Val
(
request
,
res
[
"time_id"
])
if
ok
!=
nil
{
return
nil
,
0
,
errors
.
New
(
"failed to get next available id. Extraction of id fails"
)
}
idx
,
ok
=
getIntVal
(
request
,
res
[
"_id"
])
if
ok
!=
nil
{
return
nil
,
0
,
errors
.
New
(
"failed to
next next available
id. Extraction of id fails"
)
return
nil
,
0
,
errors
.
New
(
"failed to
get _
id. Extraction of
_
id fails"
)
}
updateErr
:=
db
.
updateCurrentPointerIfEqualDB
(
request
,
curPointer
.
Value
,
int
(
nextValue
))
// If update fails, another broker already change the value. Go to the next one.
...
...
@@ -703,7 +730,7 @@ func (db *Mongodb) getRecordFromCurPointer(request Request, params ExtraParamNex
}
else
{
// In this case we can not guess, what is the next
if
err
!=
nil
{
return
nil
,
nextInd
,
err
return
nil
,
idx
,
err
}
}
...
...
@@ -711,7 +738,7 @@ func (db *Mongodb) getRecordFromCurPointer(request Request, params ExtraParamNex
return
nil
,
0
,
err
}
request
.
Logger
()
.
WithFields
(
map
[
string
]
interface
{}{
"id"
:
nextInd
})
.
Debug
(
"got record from db by id key: "
,
request
.
Logger
()
.
WithFields
(
map
[
string
]
interface
{}{
"id"
:
idx
})
.
Debug
(
"got record from db by id key: "
,
params
.
IdKey
)
record
,
err
:=
utils
.
MapToJson
(
&
res
)
...
...
@@ -720,9 +747,9 @@ func (db *Mongodb) getRecordFromCurPointer(request Request, params ExtraParamNex
return
nil
,
0
,
err
}
if
recordContainsPartialData
(
request
,
res
)
{
return
nil
,
nextInd
,
&
DBError
{
utils
.
StatusPartialData
,
string
(
record
)}
return
nil
,
idx
,
&
DBError
{
utils
.
StatusPartialData
,
string
(
record
)}
}
else
{
return
record
,
nextInd
,
nil
return
record
,
idx
,
nil
}
}
...
...
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