Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit40ceb51

Browse files
author
Alexandra Pervushina
committed
add neighbours reset, fix comments
1 parent5c77298 commit40ceb51

File tree

2 files changed

+79
-14
lines changed

2 files changed

+79
-14
lines changed

‎aqo_shared.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef struct AQOSharedState
4343
LWLockqueries_lock;/* lock for access to queries storage */
4444
boolqueries_changed;
4545

46-
LWLockneighbours_lock;/* lock for access toqueries storage */
46+
LWLockneighbours_lock;/* lock for access toneighbour storage */
4747
boolneighbours_changed;
4848
}AQOSharedState;
4949

‎storage.c‎

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ aqo_queries_flush(void)
609609
LWLockRelease(&aqo_state->queries_lock);
610610
}
611611

612+
612613
staticint
613614
data_store(constchar*filename,form_record_tcallback,
614615
longnrecs,void*ctx)
@@ -1578,7 +1579,7 @@ load_aqo_data(uint64 fs, int fss, OkNNrdata *data, List **reloids,
15781579
build_knn_matrix(data,temp_data);
15791580
}
15801581
else
1581-
/* Iterate acrossall elements of the table. XXX: Maybe slow. */
1582+
/* Iterate acrossfss neighbours. */
15821583
{
15831584
intnoids=-1;
15841585
NeighboursEntry*neighbour_entry;
@@ -1741,14 +1742,47 @@ _aqo_data_clean(uint64 fs)
17411742
hash_seq_init(&hash_seq,data_htab);
17421743
while ((entry=hash_seq_search(&hash_seq))!=NULL)
17431744
{
1745+
boolfound;
1746+
boolhas_prev= false;
1747+
boolhas_next= false;
1748+
NeighboursEntry*fss_htab_entry;
1749+
17441750
if (entry->key.fs!=fs)
17451751
continue;
17461752

17471753
Assert(DsaPointerIsValid(entry->data_dp));
17481754
dsa_free(data_dsa,entry->data_dp);
17491755
entry->data_dp=InvalidDsaPointer;
1756+
1757+
/* fix fs list */
1758+
if (entry->list.next)
1759+
has_next= true;
1760+
if (entry->list.prev)
1761+
has_prev= true;
1762+
1763+
if (has_prev)
1764+
entry->list.prev->list.next=has_next ?entry->list.next :NULL;
1765+
if (has_next)
1766+
entry->list.next->list.prev=has_prev ?entry->list.prev :NULL;
1767+
1768+
/* Fix or remove neighbours htab entry*/
1769+
LWLockAcquire(&aqo_state->neighbours_lock,LW_EXCLUSIVE);
1770+
fss_htab_entry= (NeighboursEntry*)hash_search(fss_neighbours,&entry->key.fss,HASH_FIND,&found);
1771+
if (found&&fss_htab_entry->data->key.fs==fs)
1772+
{
1773+
if (has_prev)
1774+
{
1775+
fss_htab_entry->data=entry->list.prev;
1776+
}
1777+
else
1778+
{
1779+
hash_search(fss_neighbours,&entry->key.fss,HASH_REMOVE,NULL);
1780+
}
1781+
}
1782+
LWLockRelease(&aqo_state->neighbours_lock);
1783+
17501784
if (!hash_search(data_htab,&entry->key,HASH_REMOVE,NULL))
1751-
elog(PANIC,"[AQO] hash table corrupted");
1785+
elog(ERROR,"[AQO] hash table corrupted");
17521786
removed++;
17531787
}
17541788

@@ -2048,6 +2082,32 @@ aqo_queries_update(PG_FUNCTION_ARGS)
20482082
PG_RETURN_BOOL(true);
20492083
}
20502084

2085+
staticlong
2086+
aqo_neighbours_reset(void)
2087+
{
2088+
HASH_SEQ_STATUShash_seq;
2089+
NeighboursEntry*entry;
2090+
longnum_remove=0;
2091+
longnum_entries;
2092+
2093+
LWLockAcquire(&aqo_state->neighbours_lock,LW_EXCLUSIVE);
2094+
num_entries=hash_get_num_entries(fss_neighbours);
2095+
hash_seq_init(&hash_seq,fss_neighbours);
2096+
while ((entry=hash_seq_search(&hash_seq))!=NULL)
2097+
{
2098+
if (hash_search(fss_neighbours,&entry->fss,HASH_REMOVE,NULL)==NULL)
2099+
elog(ERROR,"[AQO] hash table corrupted");
2100+
num_remove++;
2101+
}
2102+
aqo_state->neighbours_changed= true;
2103+
LWLockRelease(&aqo_state->neighbours_lock);
2104+
2105+
if (num_remove!=num_entries)
2106+
elog(ERROR,"[AQO] Neighbour memory storage is corrupted or parallel access without a lock was detected.");
2107+
2108+
returnnum_remove;
2109+
}
2110+
20512111
Datum
20522112
aqo_reset(PG_FUNCTION_ARGS)
20532113
{
@@ -2057,6 +2117,7 @@ aqo_reset(PG_FUNCTION_ARGS)
20572117
counter+=aqo_qtexts_reset();
20582118
counter+=aqo_data_reset();
20592119
counter+=aqo_queries_reset();
2120+
counter+=aqo_neighbours_reset();
20602121
PG_RETURN_INT64(counter);
20612122
}
20622123

@@ -2183,21 +2244,25 @@ cleanup_aqo_database(bool gentle, int *fs_num, int *fss_num)
21832244
entry->list.prev->list.next=has_next ?entry->list.next :NULL;
21842245
if (has_next)
21852246
entry->list.next->list.prev=has_prev ?entry->list.prev :NULL;
2186-
}
21872247

2188-
/* Fix or remove neighbours htab entry*/
2189-
fss_htab_entry= (NeighboursEntry*)hash_search(fss_neighbours,&key.fss,HASH_FIND,&found);
2190-
if (found&&fss_htab_entry->data->key.fs==key.fs)
2191-
{
2192-
if (has_prev)
2248+
/* Fix or remove neighbours htab entry*/
2249+
LWLockAcquire(&aqo_state->neighbours_lock,LW_EXCLUSIVE);
2250+
fss_htab_entry= (NeighboursEntry*)hash_search(fss_neighbours,&key.fss,HASH_FIND,&found);
2251+
if (found&&fss_htab_entry->data->key.fs==key.fs)
21932252
{
2194-
fss_htab_entry->data=entry->list.prev;
2195-
}
2196-
else
2197-
{
2198-
hash_search(fss_neighbours,&key.fss,HASH_REMOVE,NULL);
2253+
if (has_prev)
2254+
{
2255+
fss_htab_entry->data=entry->list.prev;
2256+
}
2257+
else
2258+
{
2259+
hash_search(fss_neighbours,&key.fss,HASH_REMOVE,NULL);
2260+
}
21992261
}
2262+
LWLockRelease(&aqo_state->neighbours_lock);
22002263
}
2264+
2265+
22012266
(*fss_num)+= (int)_aqo_data_remove(&key);
22022267
}
22032268

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp