Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
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
savoirfairelinux
opendht
Commits
1f3bf697
Commit
1f3bf697
authored
6 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
search: use syncStatus for get
parent
a1f8cc90
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/op_cache.cpp
+46
-9
46 additions, 9 deletions
src/op_cache.cpp
src/op_cache.h
+9
-2
9 additions, 2 deletions
src/op_cache.h
src/search.h
+5
-6
5 additions, 6 deletions
src/search.h
with
60 additions
and
17 deletions
src/op_cache.cpp
+
46
−
9
View file @
1f3bf697
...
...
@@ -108,20 +108,43 @@ OpCache::getExpiration() const {
return
lastRemoved
+
EXPIRATION
;
}
size_t
SearchCache
::
listen
(
ValueCallback
get_cb
,
Sp
<
Query
>
q
,
Value
::
Filter
filter
,
std
::
function
<
size_t
(
Sp
<
Query
>
,
ValueCallback
,
SyncCallback
)
>
onListen
)
SearchCache
::
OpMap
::
iterator
SearchCache
::
getOp
(
const
Sp
<
Query
>&
q
)
{
// find exact match
auto
op
=
ops
.
find
(
q
);
if
(
op
==
ops
.
end
())
{
if
(
op
!=
ops
.
end
())
return
op
;
// find satisfying query
for
(
auto
it
=
ops
.
begin
();
it
!=
ops
.
end
();
it
++
)
{
if
(
q
->
isSatisfiedBy
(
*
it
->
first
))
{
return
it
;
}
}
return
ops
.
end
();
}
SearchCache
::
OpMap
::
const_iterator
SearchCache
::
getOp
(
const
Sp
<
Query
>&
q
)
const
{
// find exact match
auto
op
=
ops
.
find
(
q
);
if
(
op
!=
ops
.
cend
())
return
op
;
// find satisfying query
for
(
auto
it
=
ops
.
begin
();
it
!=
ops
.
end
();
it
++
)
{
if
(
q
->
isSatisfiedBy
(
*
it
->
first
))
{
op
=
it
;
break
;
return
it
;
}
}
return
ops
.
cend
();
}
size_t
SearchCache
::
listen
(
ValueCallback
get_cb
,
Sp
<
Query
>
q
,
Value
::
Filter
filter
,
OnListen
onListen
)
{
// find exact match
auto
op
=
getOp
(
q
);
if
(
op
==
ops
.
end
())
{
// New query
op
=
ops
.
emplace
(
q
,
std
::
unique_ptr
<
OpCache
>
(
new
OpCache
)).
first
;
...
...
@@ -178,6 +201,20 @@ SearchCache::expire(const time_point& now, std::function<void(size_t)> onCancel)
return
ret
;
}
bool
SearchCache
::
get
(
const
Value
::
Filter
&
f
,
const
Sp
<
Query
>&
q
,
const
GetCallback
&
gcb
,
const
DoneCallback
&
dcb
)
const
{
auto
op
=
getOp
(
q
);
if
(
op
!=
ops
.
end
())
{
auto
vals
=
op
->
second
->
get
(
f
);
if
((
not
vals
.
empty
()
and
not
gcb
(
vals
))
or
op
->
second
->
isSynced
())
{
dcb
(
true
,
{});
return
true
;
}
}
return
false
;
}
std
::
vector
<
Sp
<
Value
>>
SearchCache
::
get
(
const
Value
::
Filter
&
filter
)
const
{
if
(
ops
.
size
()
==
1
)
...
...
This diff is collapsed.
Click to expand it.
src/op_cache.h
+
9
−
2
View file @
1f3bf697
...
...
@@ -160,7 +160,9 @@ class SearchCache {
public:
SearchCache
()
{}
SearchCache
(
SearchCache
&&
)
=
default
;
size_t
listen
(
ValueCallback
get_cb
,
Sp
<
Query
>
q
,
Value
::
Filter
filter
,
std
::
function
<
size_t
(
Sp
<
Query
>
,
ValueCallback
,
SyncCallback
)
>
onListen
);
using
OnListen
=
std
::
function
<
size_t
(
Sp
<
Query
>
,
ValueCallback
,
SyncCallback
)
>
;
size_t
listen
(
ValueCallback
get_cb
,
Sp
<
Query
>
q
,
Value
::
Filter
filter
,
OnListen
onListen
);
bool
cancelListen
(
size_t
gtoken
,
const
time_point
&
now
);
void
cancelAll
(
std
::
function
<
void
(
size_t
)
>
onCancel
);
...
...
@@ -170,6 +172,7 @@ public:
return
nextExpiration_
;
}
bool
get
(
const
Value
::
Filter
&
f
,
const
Sp
<
Query
>&
q
,
const
GetCallback
&
gcb
,
const
DoneCallback
&
dcb
)
const
;
std
::
vector
<
Sp
<
Value
>>
get
(
const
Value
::
Filter
&
filter
)
const
;
Sp
<
Value
>
get
(
Value
::
Id
id
)
const
;
...
...
@@ -177,7 +180,11 @@ private:
SearchCache
(
const
SearchCache
&
)
=
delete
;
SearchCache
&
operator
=
(
const
SearchCache
&
)
=
delete
;
std
::
map
<
Sp
<
Query
>
,
std
::
unique_ptr
<
OpCache
>>
ops
{};
using
OpMap
=
std
::
map
<
Sp
<
Query
>
,
std
::
unique_ptr
<
OpCache
>>
;
OpMap
ops
{};
OpMap
::
iterator
getOp
(
const
Sp
<
Query
>&
q
);
OpMap
::
const_iterator
getOp
(
const
Sp
<
Query
>&
q
)
const
;
size_t
nextToken_
{
1
};
time_point
nextExpiration_
{
time_point
::
max
()};
};
...
...
This diff is collapsed.
Click to expand it.
src/search.h
+
5
−
6
View file @
1f3bf697
...
...
@@ -491,14 +491,13 @@ struct Dht::Search {
void
get
(
Value
::
Filter
f
,
const
Sp
<
Query
>&
q
,
const
QueryCallback
&
qcb
,
const
GetCallback
&
gcb
,
const
DoneCallback
&
dcb
,
Scheduler
&
scheduler
)
{
if
(
gcb
or
qcb
)
{
if
(
not
cache
.
get
(
f
,
q
,
gcb
,
dcb
))
{
const
auto
&
now
=
scheduler
.
time
();
callbacks
.
emplace
(
now
,
Get
{
now
,
f
,
q
,
qcb
,
gcb
,
dcb
});
auto
values
=
cache
.
get
(
f
);
if
(
not
values
.
empty
())
gcb
(
values
);
scheduler
.
edit
(
nextSearchStep
,
now
);
}
}
}
size_t
listen
(
ValueCallback
cb
,
Value
::
Filter
f
,
const
Sp
<
Query
>&
q
,
Scheduler
&
scheduler
)
{
//DHT_LOG.e(id, "[search %s IPv%c] listen", id.toString().c_str(), (af == AF_INET) ? '4' : '6');
...
...
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