Skip to content

Commit

Permalink
Remove unused argument tuplelock in hypertable_scan_limit_internal
Browse files Browse the repository at this point in the history
The tuplelock argument was never used in hypertable_scan_limit_internal.
This patch removes it and also removes some other unused functions related
to locking.
  • Loading branch information
svenklemm committed Dec 8, 2023
1 parent aacc6b5 commit d3e0c2b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 99 deletions.
95 changes: 3 additions & 92 deletions src/hypertable.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,7 @@ hypertable_filter_exclude_compressed_and_materialization(const TupleInfo *ti, vo
static int
hypertable_scan_limit_internal(ScanKeyData *scankey, int num_scankeys, int indexid,
tuple_found_func on_tuple_found, void *scandata, int limit,
LOCKMODE lock, bool tuplock, MemoryContext mctx,
tuple_filter_func filter)
LOCKMODE lock, MemoryContext mctx, tuple_filter_func filter)
{
Catalog *catalog = ts_catalog_get();
ScannerCtx scanctx = {
Expand Down Expand Up @@ -458,7 +457,6 @@ ts_hypertable_get_all(void)
&result,
-1,
RowExclusiveLock,
false,
CurrentMemoryContext,
hypertable_filter_exclude_compressed_and_materialization);

Expand Down Expand Up @@ -516,15 +514,14 @@ ts_hypertable_update(Hypertable *ht)
ht,
1,
RowExclusiveLock,
false,
CurrentMemoryContext,
NULL);
}

int
ts_hypertable_scan_with_memory_context(const char *schema, const char *table,
tuple_found_func tuple_found, void *data, LOCKMODE lockmode,
bool tuplock, MemoryContext mctx)
MemoryContext mctx)
{
ScanKeyData scankey[2];
NameData schema_name = { .data = { 0 } };
Expand Down Expand Up @@ -555,7 +552,6 @@ ts_hypertable_scan_with_memory_context(const char *schema, const char *table,
data,
1,
lockmode,
tuplock,
mctx,
NULL);
}
Expand Down Expand Up @@ -729,7 +725,6 @@ ts_hypertable_delete_by_name(const char *schema_name, const char *table_name)
NULL,
0,
RowExclusiveLock,
false,
CurrentMemoryContext,
NULL);
}
Expand All @@ -752,7 +747,6 @@ ts_hypertable_delete_by_id(int32 hypertable_id)
NULL,
1,
RowExclusiveLock,
false,
CurrentMemoryContext,
NULL);
}
Expand Down Expand Up @@ -815,92 +809,10 @@ ts_hypertable_reset_associated_schema_name(const char *associated_schema)
NULL,
0,
RowExclusiveLock,
false,
CurrentMemoryContext,
NULL);
}

static ScanTupleResult
tuple_found_lock(TupleInfo *ti, void *data)
{
TM_Result *result = data;

*result = ti->lockresult;
return SCAN_DONE;
}

TM_Result
ts_hypertable_lock_tuple(Oid table_relid)
{
TM_Result result;
int num_found;

num_found = hypertable_scan(get_namespace_name(get_rel_namespace(table_relid)),
get_rel_name(table_relid),
tuple_found_lock,
&result,
RowExclusiveLock,
true);

if (num_found != 1)
ereport(ERROR,
(errcode(ERRCODE_TS_HYPERTABLE_NOT_EXIST),
errmsg("table \"%s\" is not a hypertable", get_rel_name(table_relid))));

return result;
}

bool
ts_hypertable_lock_tuple_simple(Oid table_relid)
{
TM_Result result = ts_hypertable_lock_tuple(table_relid);

switch (result)
{
case TM_SelfModified:

/*
* Updated by the current transaction already. We equate this with
* a successful lock since the tuple should be locked if updated
* by us.
*/
return true;
case TM_Ok:
/* successfully locked */
return true;

case TM_Deleted:
case TM_Updated:
ereport(ERROR,
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
errmsg("hypertable \"%s\" has already been updated by another transaction",
get_rel_name(table_relid)),
errhint("Retry the operation again.")));
pg_unreachable();
return false;

case TM_BeingModified:
ereport(ERROR,
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
errmsg("hypertable \"%s\" is being updated by another transaction",
get_rel_name(table_relid)),
errhint("Retry the operation again.")));
pg_unreachable();
return false;
case TM_WouldBlock:
/* Locking would block. Let caller decide what to do */
return false;
case TM_Invisible:
elog(ERROR, "attempted to lock invisible tuple");
pg_unreachable();
return false;
default:
elog(ERROR, "unexpected tuple lock status");
pg_unreachable();
return false;
}
}

int
ts_hypertable_set_name(Hypertable *ht, const char *newname)
{
Expand Down Expand Up @@ -1033,7 +945,7 @@ ts_hypertable_get_by_name(const char *schema, const char *name)
{
Hypertable *ht = NULL;

hypertable_scan(schema, name, hypertable_tuple_found, &ht, AccessShareLock, false);
hypertable_scan(schema, name, hypertable_tuple_found, &ht, AccessShareLock);

return ht;
}
Expand Down Expand Up @@ -1107,7 +1019,6 @@ ts_hypertable_get_by_id(int32 hypertable_id)
&ht,
1,
AccessShareLock,
false,
CurrentMemoryContext,
NULL);
return ht;
Expand Down
8 changes: 2 additions & 6 deletions src/hypertable.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ extern Hypertable *ts_resolve_hypertable_from_table_or_cagg(Cache *hcache, Oid r
bool allow_matht);
extern int ts_hypertable_scan_with_memory_context(const char *schema, const char *table,
tuple_found_func tuple_found, void *data,
LOCKMODE lockmode, bool tuplock,
MemoryContext mctx);
extern TM_Result ts_hypertable_lock_tuple(Oid table_relid);
extern bool ts_hypertable_lock_tuple_simple(Oid table_relid);
LOCKMODE lockmode, MemoryContext mctx);
extern TSDLLEXPORT int ts_hypertable_update(Hypertable *ht);
extern int ts_hypertable_set_name(Hypertable *ht, const char *newname);
extern int ts_hypertable_set_schema(Hypertable *ht, const char *newname);
Expand Down Expand Up @@ -190,13 +187,12 @@ extern TSDLLEXPORT int16 ts_validate_replication_factor(const char *hypertable_n
int32 replication_factor,
int num_data_nodes);

#define hypertable_scan(schema, table, tuple_found, data, lockmode, tuplock) \
#define hypertable_scan(schema, table, tuple_found, data, lockmode) \
ts_hypertable_scan_with_memory_context(schema, \
table, \
tuple_found, \
data, \
lockmode, \
tuplock, \
CurrentMemoryContext)

#define hypertable_adaptive_chunking_enabled(ht) \
Expand Down
1 change: 0 additions & 1 deletion src/hypertable_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ hypertable_cache_create_entry(Cache *cache, CacheQuery *query)
hypertable_tuple_found,
query->result,
AccessShareLock,
false,
ts_cache_memory_ctx(cache));

switch (number_found)
Expand Down

0 comments on commit d3e0c2b

Please sign in to comment.