Commit 94f282b1 authored by Paras Garg's avatar Paras Garg

changed Makefile and added conf file

parent 3ecce2f2
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/home/paras/git/postgres/install/include/server"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
\ No newline at end of file
...@@ -5,17 +5,13 @@ PGFILEDESC = "lsm tree index based on existing btree index" ...@@ -5,17 +5,13 @@ PGFILEDESC = "lsm tree index based on existing btree index"
EXTENSION = lsm EXTENSION = lsm
DATA = lsm--1.0.sql DATA = lsm--1.0.sql
REGRESS = test #REGRESS = test
REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/lsm3/lsm3.conf #REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/lsm3/lsm3.conf
ifdef USE_PGXS
PG_CONFIG ?= pg_config # postgres build stuff
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs) PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS) include $(PGXS)
else
subdir = contrib/lsm3
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
...@@ -31,47 +31,47 @@ ...@@ -31,47 +31,47 @@
#include "storage/lmgr.h" #include "storage/lmgr.h"
#include "storage/procarray.h" #include "storage/procarray.h"
#include "lsm3.h" #include "lsm.h"
#ifdef PG_MODULE_MAGIC #ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC; PG_MODULE_MAGIC;
#endif #endif
PG_FUNCTION_INFO_V1(lsm3_handler); PG_FUNCTION_INFO_V1(lsm_handler);
PG_FUNCTION_INFO_V1(lsm3_btree_wrapper); PG_FUNCTION_INFO_V1(lsm_btree_wrapper);
PG_FUNCTION_INFO_V1(lsm3_get_merge_count); PG_FUNCTION_INFO_V1(lsm_get_merge_count);
PG_FUNCTION_INFO_V1(lsm3_start_merge); PG_FUNCTION_INFO_V1(lsm_start_merge);
PG_FUNCTION_INFO_V1(lsm3_wait_merge_completion); PG_FUNCTION_INFO_V1(lsm_wait_merge_completion);
PG_FUNCTION_INFO_V1(lsm3_top_index_size); PG_FUNCTION_INFO_V1(lsm_top_index_size);
extern void _PG_init(void); extern void _PG_init(void);
extern void _PG_fini(void); extern void _PG_fini(void);
extern void lsm3_merger_main(Datum arg); extern void lsm_merger_main(Datum arg);
/* Lsm3 dictionary (hashtable with control data for all indexes) */ /* lsm dictionary (hashtable with control data for all indexes) */
static Lsm3DictEntry* Lsm3Entry; static lsmDictEntry* lsmEntry;
static HTAB* Lsm3Dict; static HTAB* lsmDict;
static LWLock* Lsm3DictLock; static LWLock* lsmDictLock;
static List* Lsm3ReleasedLocks; static List* lsmReleasedLocks;
/* Kind of relation optioms for Lsm3 index */ /* Kind of relation optioms for lsm index */
static relopt_kind Lsm3ReloptKind; static relopt_kind lsmReloptKind;
/* Lsm3 kooks */ /* lsm kooks */
static ProcessUtility_hook_type PreviousProcessUtilityHook = NULL; static ProcessUtility_hook_type PreviousProcessUtilityHook = NULL;
static shmem_startup_hook_type PreviousShmemStartupHook = NULL; static shmem_startup_hook_type PreviousShmemStartupHook = NULL;
static ExecutorFinish_hook_type PreviousExecutorFinish = NULL; static ExecutorFinish_hook_type PreviousExecutorFinish = NULL;
/* Lsm3 GUCs */ /* lsm GUCs */
static int Lsm3MaxIndexes; static int lsmMaxIndexes;
static int Lsm3TopIndexSize; static int lsmTopIndexSize;
/* Background worker termination flag */ /* Background worker termination flag */
static volatile bool Lsm3Cancel; static volatile bool lsmCancel;
static void static void
lsm3_shmem_startup(void) lsm_shmem_startup(void)
{ {
HASHCTL info; HASHCTL info;
...@@ -81,17 +81,17 @@ lsm3_shmem_startup(void) ...@@ -81,17 +81,17 @@ lsm3_shmem_startup(void)
} }
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
info.keysize = sizeof(Oid); info.keysize = sizeof(Oid);
info.entrysize = sizeof(Lsm3DictEntry); info.entrysize = sizeof(lsmDictEntry);
Lsm3Dict = ShmemInitHash("lsm3 hash", lsmDict = ShmemInitHash("lsm hash",
Lsm3MaxIndexes, Lsm3MaxIndexes, lsmMaxIndexes, lsmMaxIndexes,
&info, &info,
HASH_ELEM | HASH_BLOBS); HASH_ELEM | HASH_BLOBS);
Lsm3DictLock = &(GetNamedLWLockTranche("lsm3"))->lock; lsmDictLock = &(GetNamedLWLockTranche("lsm"))->lock;
} }
/* Initialize Lsm3 control data entry */ /* Initialize lsm control data entry */
static void static void
lsm3_init_entry(Lsm3DictEntry* entry, Relation index) lsm_init_entry(lsmDictEntry* entry, Relation index)
{ {
SpinLockInit(&entry->spinlock); SpinLockInit(&entry->spinlock);
entry->active_index = 0; entry->active_index = 0;
...@@ -105,12 +105,12 @@ lsm3_init_entry(Lsm3DictEntry* entry, Relation index) ...@@ -105,12 +105,12 @@ lsm3_init_entry(Lsm3DictEntry* entry, Relation index)
entry->heap = index->rd_index->indrelid; entry->heap = index->rd_index->indrelid;
entry->db_id = MyDatabaseId; entry->db_id = MyDatabaseId;
entry->user_id = GetUserId(); entry->user_id = GetUserId();
entry->top_index_size = index->rd_options ? ((Lsm3Options*)index->rd_options)->top_index_size : 0; entry->top_index_size = index->rd_options ? ((lsmOptions*)index->rd_options)->top_index_size : 0;
} }
/* Get B-Tree index size (number of blocks) */ /* Get B-Tree index size (number of blocks) */
static BlockNumber static BlockNumber
lsm3_get_index_size(Oid relid) lsm_get_index_size(Oid relid)
{ {
Relation index = index_open(relid, AccessShareLock); Relation index = index_open(relid, AccessShareLock);
BlockNumber size = RelationGetNumberOfBlocks(index); BlockNumber size = RelationGetNumberOfBlocks(index);
...@@ -118,66 +118,66 @@ lsm3_get_index_size(Oid relid) ...@@ -118,66 +118,66 @@ lsm3_get_index_size(Oid relid)
return size; return size;
} }
/* Lookup or create Lsm3 control data for this index */ /* Lookup or create lsm control data for this index */
static Lsm3DictEntry* static lsmDictEntry*
lsm3_get_entry(Relation index) lsm_get_entry(Relation index)
{ {
Lsm3DictEntry* entry; lsmDictEntry* entry;
bool found = true; bool found = true;
LWLockAcquire(Lsm3DictLock, LW_SHARED); LWLockAcquire(lsmDictLock, LW_SHARED);
entry = (Lsm3DictEntry*)hash_search(Lsm3Dict, &RelationGetRelid(index), HASH_FIND, &found); entry = (lsmDictEntry*)hash_search(lsmDict, &RelationGetRelid(index), HASH_FIND, &found);
if (entry == NULL) if (entry == NULL)
{ {
/* We need exclusive lock to create new entry */ /* We need exclusive lock to create new entry */
LWLockRelease(Lsm3DictLock); LWLockRelease(lsmDictLock);
LWLockAcquire(Lsm3DictLock, LW_EXCLUSIVE); LWLockAcquire(lsmDictLock, LW_EXCLUSIVE);
entry = (Lsm3DictEntry*)hash_search(Lsm3Dict, &RelationGetRelid(index), HASH_ENTER, &found); entry = (lsmDictEntry*)hash_search(lsmDict, &RelationGetRelid(index), HASH_ENTER, &found);
} }
if (!found) if (!found)
{ {
char* relname = RelationGetRelationName(index); char* relname = RelationGetRelationName(index);
lsm3_init_entry(entry, index); lsm_init_entry(entry, index);
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
char* topidxname = psprintf("%s_top%d", relname, i); char* topidxname = psprintf("%s_top%d", relname, i);
entry->top[i] = get_relname_relid(topidxname, RelationGetNamespace(index)); entry->top[i] = get_relname_relid(topidxname, RelationGetNamespace(index));
if (entry->top[i] == InvalidOid) if (entry->top[i] == InvalidOid)
{ {
elog(ERROR, "Lsm3: failed to lookup %s index", topidxname); elog(ERROR, "lsm: failed to lookup %s index", topidxname);
} }
} }
entry->active_index = lsm3_get_index_size(entry->top[0]) >= lsm3_get_index_size(entry->top[1]) ? 0 : 1; entry->active_index = lsm_get_index_size(entry->top[0]) >= lsm_get_index_size(entry->top[1]) ? 0 : 1;
} }
LWLockRelease(Lsm3DictLock); LWLockRelease(lsmDictLock);
return entry; return entry;
} }
/* Launch merger bgworker */ /* Launch merger bgworker */
static void static void
lsm3_launch_bgworker(Lsm3DictEntry* entry) lsm_launch_bgworker(lsmDictEntry* entry)
{ {
BackgroundWorker worker; BackgroundWorker worker;
BackgroundWorkerHandle *handle; BackgroundWorkerHandle *handle;
pid_t bgw_pid; pid_t bgw_pid;
MemSet(&worker, 0, sizeof(worker)); MemSet(&worker, 0, sizeof(worker));
snprintf(worker.bgw_name, sizeof(worker.bgw_name), "lsm3-merger-%d", entry->base); snprintf(worker.bgw_name, sizeof(worker.bgw_name), "lsm-merger-%d", entry->base);
snprintf(worker.bgw_type, sizeof(worker.bgw_type), "lsm3-merger-%d", entry->base); snprintf(worker.bgw_type, sizeof(worker.bgw_type), "lsm-merger-%d", entry->base);
worker.bgw_flags = BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION; worker.bgw_flags = BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION;
worker.bgw_start_time = BgWorkerStart_ConsistentState; worker.bgw_start_time = BgWorkerStart_ConsistentState;
worker.bgw_restart_time = BGW_NEVER_RESTART; worker.bgw_restart_time = BGW_NEVER_RESTART;
strcpy(worker.bgw_function_name, "lsm3_merger_main"); strcpy(worker.bgw_function_name, "lsm_merger_main");
strcpy(worker.bgw_library_name, "lsm3"); strcpy(worker.bgw_library_name, "lsm");
worker.bgw_main_arg = PointerGetDatum(entry); worker.bgw_main_arg = PointerGetDatum(entry);
worker.bgw_notify_pid = MyProcPid; worker.bgw_notify_pid = MyProcPid;
if (!RegisterDynamicBackgroundWorker(&worker, &handle)) if (!RegisterDynamicBackgroundWorker(&worker, &handle))
{ {
elog(ERROR, "Lsm3: failed to start background worker"); elog(ERROR, "lsm: failed to start background worker");
} }
if (WaitForBackgroundWorkerStartup(handle, &bgw_pid) != BGWH_STARTED) if (WaitForBackgroundWorkerStartup(handle, &bgw_pid) != BGWH_STARTED)
{ {
elog(ERROR, "Lsm3: startup of background worker is failed"); elog(ERROR, "lsm: startup of background worker is failed");
} }
entry->merger = BackendPidGetProc(bgw_pid); entry->merger = BackendPidGetProc(bgw_pid);
for (int n_attempts = 0; entry->merger == NULL || n_attempts < 100; n_attempts++) for (int n_attempts = 0; entry->merger == NULL || n_attempts < 100; n_attempts++)
...@@ -187,27 +187,27 @@ lsm3_launch_bgworker(Lsm3DictEntry* entry) ...@@ -187,27 +187,27 @@ lsm3_launch_bgworker(Lsm3DictEntry* entry)
} }
if (entry->merger == NULL) if (entry->merger == NULL)
{ {
elog(ERROR, "Lsm3: background worker %d is crashed", bgw_pid); elog(ERROR, "lsm: background worker %d is crashed", bgw_pid);
} }
} }
/* Cancel merger bgwroker */ /* Cancel merger bgwroker */
static void static void
lsm3_merge_cancel(int sig) lsm_merge_cancel(int sig)
{ {
Lsm3Cancel = true; lsmCancel = true;
SetLatch(MyLatch); SetLatch(MyLatch);
} }
/* Truncate top index */ /* Truncate top index */
static void static void
lsm3_truncate_index(Oid index_oid, Oid heap_oid) lsm_truncate_index(Oid index_oid, Oid heap_oid)
{ {
Relation index = index_open(index_oid, AccessExclusiveLock); Relation index = index_open(index_oid, AccessExclusiveLock);
Relation heap = table_open(heap_oid, AccessShareLock); /* heap is actually not used, because we will not load data to top indexes */ Relation heap = table_open(heap_oid, AccessShareLock); /* heap is actually not used, because we will not load data to top indexes */
IndexInfo* indexInfo = BuildDummyIndexInfo(index); IndexInfo* indexInfo = BuildDummyIndexInfo(index);
RelationTruncate(index, 0); RelationTruncate(index, 0);
elog(LOG, "Lsm3: truncate index %s", RelationGetRelationName(index)); elog(LOG, "lsm: truncate index %s", RelationGetRelationName(index));
index_build(heap, index, indexInfo, true, false); index_build(heap, index, indexInfo, true, false);
index_close(index, AccessExclusiveLock); index_close(index, AccessExclusiveLock);
table_close(heap, AccessShareLock); table_close(heap, AccessShareLock);
...@@ -215,7 +215,7 @@ lsm3_truncate_index(Oid index_oid, Oid heap_oid) ...@@ -215,7 +215,7 @@ lsm3_truncate_index(Oid index_oid, Oid heap_oid)
/* Merge top index into base index */ /* Merge top index into base index */
static void static void
lsm3_merge_indexes(Oid dst_oid, Oid src_oid, Oid heap_oid) lsm_merge_indexes(Oid dst_oid, Oid src_oid, Oid heap_oid)
{ {
Relation top_index = index_open(src_oid, AccessShareLock); Relation top_index = index_open(src_oid, AccessShareLock);
Relation heap = table_open(heap_oid, AccessShareLock); Relation heap = table_open(heap_oid, AccessShareLock);
...@@ -224,7 +224,7 @@ lsm3_merge_indexes(Oid dst_oid, Oid src_oid, Oid heap_oid) ...@@ -224,7 +224,7 @@ lsm3_merge_indexes(Oid dst_oid, Oid src_oid, Oid heap_oid)
bool ok; bool ok;
Oid save_am = base_index->rd_rel->relam; Oid save_am = base_index->rd_rel->relam;
elog(LOG, "Lsm3: merge top index %s with size %d blocks", RelationGetRelationName(top_index), RelationGetNumberOfBlocks(top_index)); elog(LOG, "lsm: merge top index %s with size %d blocks", RelationGetRelationName(top_index), RelationGetNumberOfBlocks(top_index));
base_index->rd_rel->relam = BTREE_AM_OID; base_index->rd_rel->relam = BTREE_AM_OID;
scan = index_beginscan(heap, top_index, SnapshotAny, 0, 0); scan = index_beginscan(heap, top_index, SnapshotAny, 0, 0);
...@@ -247,14 +247,14 @@ lsm3_merge_indexes(Oid dst_oid, Oid src_oid, Oid heap_oid) ...@@ -247,14 +247,14 @@ lsm3_merge_indexes(Oid dst_oid, Oid src_oid, Oid heap_oid)
unsigned short save_info = itup->t_info; unsigned short save_info = itup->t_info;
itup->t_info = (save_info & ~(INDEX_SIZE_MASK | INDEX_ALT_TID_MASK)) + BTreeTupleGetPostingOffset(itup); itup->t_info = (save_info & ~(INDEX_SIZE_MASK | INDEX_ALT_TID_MASK)) + BTreeTupleGetPostingOffset(itup);
itup->t_tid = scan->xs_heaptid; itup->t_tid = scan->xs_heaptid;
_bt_doinsert(base_index, itup, false, heap); /* lsm3 index is not unique so need not to heck for duplica _bt_doinsert(base_index, itup, false, heap); /* lsm index is not unique so need not to heck for duplica
tes */ tes */
itup->t_tid = save_tid; itup->t_tid = save_tid;
itup->t_info = save_info; itup->t_info = save_info;
} }
else else
{ {
_bt_doinsert(base_index, itup, false, heap); /* lsm3 index is not unique so need not to heck for duplica _bt_doinsert(base_index, itup, false, heap); /* lsm index is not unique so need not to heck for duplica
tes */ tes */
} }
} }
...@@ -265,10 +265,10 @@ tes */ ...@@ -265,10 +265,10 @@ tes */
table_close(heap, AccessShareLock); table_close(heap, AccessShareLock);
} }
/* Lsm3 index options. /* lsm index options.
*/ */
static bytea * static bytea *
lsm3_options(Datum reloptions, bool validate) lsm_options(Datum reloptions, bool validate)
{ {
static const relopt_parse_elt tab[] = { static const relopt_parse_elt tab[] = {
{"fillfactor", RELOPT_TYPE_INT, offsetof(BTOptions, fillfactor)}, {"fillfactor", RELOPT_TYPE_INT, offsetof(BTOptions, fillfactor)},
...@@ -276,41 +276,41 @@ lsm3_options(Datum reloptions, bool validate) ...@@ -276,41 +276,41 @@ lsm3_options(Datum reloptions, bool validate)
offsetof(BTOptions, vacuum_cleanup_index_scale_factor)}, offsetof(BTOptions, vacuum_cleanup_index_scale_factor)},
{"deduplicate_items", RELOPT_TYPE_BOOL, {"deduplicate_items", RELOPT_TYPE_BOOL,
offsetof(BTOptions, deduplicate_items)}, offsetof(BTOptions, deduplicate_items)},
{"top_index_size", RELOPT_TYPE_INT, offsetof(Lsm3Options, top_index_size)}, {"top_index_size", RELOPT_TYPE_INT, offsetof(lsmOptions, top_index_size)},
{"unique", RELOPT_TYPE_BOOL, offsetof(Lsm3Options, unique)} {"unique", RELOPT_TYPE_BOOL, offsetof(lsmOptions, unique)}
}; };
return (bytea *) build_reloptions(reloptions, validate, Lsm3ReloptKind, return (bytea *) build_reloptions(reloptions, validate, lsmReloptKind,
sizeof(Lsm3Options), tab, lengthof(tab)); sizeof(lsmOptions), tab, lengthof(tab));
} }
/* Main function of merger bgwroker */ /* Main function of merger bgwroker */
void void
lsm3_merger_main(Datum arg) lsm_merger_main(Datum arg)
{ {
Lsm3DictEntry* entry = (Lsm3DictEntry*)DatumGetPointer(arg); lsmDictEntry* entry = (lsmDictEntry*)DatumGetPointer(arg);
char *appname; char *appname;
pqsignal(SIGINT, lsm3_merge_cancel); pqsignal(SIGINT, lsm_merge_cancel);
pqsignal(SIGQUIT, lsm3_merge_cancel); pqsignal(SIGQUIT, lsm_merge_cancel);
pqsignal(SIGTERM, lsm3_merge_cancel); pqsignal(SIGTERM, lsm_merge_cancel);
/* We're now ready to receive signals */ /* We're now ready to receive signals */
BackgroundWorkerUnblockSignals(); BackgroundWorkerUnblockSignals();
BackgroundWorkerInitializeConnectionByOid(entry->db_id, entry->user_id, 0); BackgroundWorkerInitializeConnectionByOid(entry->db_id, entry->user_id, 0);
appname = psprintf("lsm3 merger for %d", entry->base); appname = psprintf("lsm merger for %d", entry->base);
pgstat_report_appname(appname); pgstat_report_appname(appname);
pfree(appname); pfree(appname);
while (!Lsm3Cancel) while (!lsmCancel)
{ {
int merge_index= -1; int merge_index= -1;
int wr; int wr;
pgstat_report_activity(STATE_IDLE, "waiting"); pgstat_report_activity(STATE_IDLE, "waiting");
wr = WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, -1L, PG_WAIT_EXTENSION); wr = WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, -1L, PG_WAIT_EXTENSION);
if ((wr & WL_POSTMASTER_DEATH) || Lsm3Cancel) if ((wr & WL_POSTMASTER_DEATH) || lsmCancel)
{ {
break; break;
} }
...@@ -331,10 +331,10 @@ lsm3_merger_main(Datum arg) ...@@ -331,10 +331,10 @@ lsm3_merger_main(Datum arg)
StartTransactionCommand(); StartTransactionCommand();
{ {
pgstat_report_activity(STATE_RUNNING, "merging"); pgstat_report_activity(STATE_RUNNING, "merging");
lsm3_merge_indexes(entry->base, entry->top[merge_index], entry->heap); lsm_merge_indexes(entry->base, entry->top[merge_index], entry->heap);
pgstat_report_activity(STATE_RUNNING, "truncate"); pgstat_report_activity(STATE_RUNNING, "truncate");
lsm3_truncate_index(entry->top[merge_index], entry->heap); lsm_truncate_index(entry->top[merge_index], entry->heap);
} }
CommitTransactionCommand(); CommitTransactionCommand();
...@@ -348,7 +348,7 @@ lsm3_merger_main(Datum arg) ...@@ -348,7 +348,7 @@ lsm3_merger_main(Datum arg)
/* Build index tuple comparator context */ /* Build index tuple comparator context */
static SortSupport static SortSupport
lsm3_build_sortkeys(Relation index) lsm_build_sortkeys(Relation index)
{ {
int keysz = IndexRelationGetNumberOfKeyAttributes(index); int keysz = IndexRelationGetNumberOfKeyAttributes(index);
SortSupport sortKeys = (SortSupport) palloc0(keysz * sizeof(SortSupportData)); SortSupport sortKeys = (SortSupport) palloc0(keysz * sizeof(SortSupportData));
...@@ -384,7 +384,7 @@ lsm3_build_sortkeys(Relation index) ...@@ -384,7 +384,7 @@ lsm3_build_sortkeys(Relation index)
/* Compare index tuples */ /* Compare index tuples */
static int static int
lsm3_compare_index_tuples(IndexScanDesc scan1, IndexScanDesc scan2, SortSupport sortKeys) lsm_compare_index_tuples(IndexScanDesc scan1, IndexScanDesc scan2, SortSupport sortKeys)
{ {
int n_keys = IndexRelationGetNumberOfKeyAttributes(scan1->indexRelation); int n_keys = IndexRelationGetNumberOfKeyAttributes(scan1->indexRelation);
...@@ -408,20 +408,20 @@ lsm3_compare_index_tuples(IndexScanDesc scan1, IndexScanDesc scan2, SortSupport ...@@ -408,20 +408,20 @@ lsm3_compare_index_tuples(IndexScanDesc scan1, IndexScanDesc scan2, SortSupport
} }
/* /*
* Lsm3 access methods implementation * lsm access methods implementation
*/ */
static IndexBuildResult * static IndexBuildResult *
lsm3_build(Relation heap, Relation index, IndexInfo *indexInfo) lsm_build(Relation heap, Relation index, IndexInfo *indexInfo)
{ {
Oid save_am = index->rd_rel->relam; Oid save_am = index->rd_rel->relam;
IndexBuildResult * result; IndexBuildResult * result;
bool found; bool found;
LWLockAcquire(Lsm3DictLock, LW_EXCLUSIVE); /* Obtain exclusive lock on dictionary: it will be released in utility hook */ LWLockAcquire(lsmDictLock, LW_EXCLUSIVE); /* Obtain exclusive lock on dictionary: it will be released in utility hook */
Lsm3Entry = hash_search(Lsm3Dict, &RelationGetRelid(index), HASH_ENTER, &found); /* Setting Lsm3Entry indicates to utility hook that Lsm3 index was created */ lsmEntry = hash_search(lsmDict, &RelationGetRelid(index), HASH_ENTER, &found); /* Setting lsmEntry indicates to utility hook that lsm index was created */
if (!found) if (!found)
{ {
lsm3_init_entry(Lsm3Entry, index); lsm_init_entry(lsmEntry, index);
} }
index->rd_rel->relam = BTREE_AM_OID; index->rd_rel->relam = BTREE_AM_OID;
result = btbuild(heap, index, indexInfo); result = btbuild(heap, index, indexInfo);
...@@ -432,19 +432,19 @@ lsm3_build(Relation heap, Relation index, IndexInfo *indexInfo) ...@@ -432,19 +432,19 @@ lsm3_build(Relation heap, Relation index, IndexInfo *indexInfo)
/* Insert in active top index, on overflow swap active indexes and initiate merge to base index */ /* Insert in active top index, on overflow swap active indexes and initiate merge to base index */
static bool static bool
lsm3_insert(Relation rel, Datum *values, bool *isnull, lsm_insert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel, ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique, IndexUniqueCheck checkUnique,
IndexInfo *indexInfo) IndexInfo *indexInfo)
{ {
Lsm3DictEntry* entry = lsm3_get_entry(rel); lsmDictEntry* entry = lsm_get_entry(rel);
int active_index; int active_index;
uint64 n_merges; /* used to check if merge was initiated by somebody else */ uint64 n_merges; /* used to check if merge was initiated by somebody else */
Relation index; Relation index;
Oid save_am; Oid save_am;
bool overflow; bool overflow;
int top_index_size = entry->top_index_size ? entry->top_index_size : Lsm3TopIndexSize; int top_index_size = entry->top_index_size ? entry->top_index_size : lsmTopIndexSize;
/* Obtain current active index and increment access counter under spinlock */ /* Obtain current active index and increment access counter under spinlock */
SpinLockAcquire(&entry->spinlock); SpinLockAcquire(&entry->spinlock);
...@@ -462,7 +462,7 @@ lsm3_insert(Relation rel, Datum *values, bool *isnull, ...@@ -462,7 +462,7 @@ lsm3_insert(Relation rel, Datum *values, bool *isnull,
index->rd_rel->relam = save_am; index->rd_rel->relam = save_am;
overflow = !entry->merge_in_progress /* do not check for overflow if merge was already initiated */ overflow = !entry->merge_in_progress /* do not check for overflow if merge was already initiated */
&& (entry->n_inserts % LSM3_CHECK_TOP_INDEX_SIZE_PERIOD) == 0 /* perform check only each N-th insert */ && (entry->n_inserts % lsm_CHECK_TOP_INDEX_SIZE_PERIOD) == 0 /* perform check only each N-th insert */
&& RelationGetNumberOfBlocks(index)*(BLCKSZ/1024) > top_index_size; && RelationGetNumberOfBlocks(index)*(BLCKSZ/1024) > top_index_size;
SpinLockAcquire(&entry->spinlock); SpinLockAcquire(&entry->spinlock);
...@@ -487,7 +487,7 @@ lsm3_insert(Relation rel, Datum *values, bool *isnull, ...@@ -487,7 +487,7 @@ lsm3_insert(Relation rel, Datum *values, bool *isnull,
if (LockHeldByMe(&tag, RowExclusiveLock)) if (LockHeldByMe(&tag, RowExclusiveLock))
{ {
LockRelease(&tag, RowExclusiveLock, false); LockRelease(&tag, RowExclusiveLock, false);
Lsm3ReleasedLocks = lappend_oid(Lsm3ReleasedLocks, entry->top[1-active_index]); lsmReleasedLocks = lappend_oid(lsmReleasedLocks, entry->top[1-active_index]);
} }
/* If all inserts in previous active index are completed then we can start merge */ /* If all inserts in previous active index are completed then we can start merge */
...@@ -496,7 +496,7 @@ lsm3_insert(Relation rel, Datum *values, bool *isnull, ...@@ -496,7 +496,7 @@ lsm3_insert(Relation rel, Datum *values, bool *isnull,
entry->start_merge = true; entry->start_merge = true;
if (entry->merger == NULL) /* lazy start of bgworker */ if (entry->merger == NULL) /* lazy start of bgworker */
{ {
lsm3_launch_bgworker(entry); lsm_launch_bgworker(entry);
} }
SetLatch(&entry->merger->procLatch); SetLatch(&entry->merger->procLatch);
} }
...@@ -507,10 +507,10 @@ lsm3_insert(Relation rel, Datum *values, bool *isnull, ...@@ -507,10 +507,10 @@ lsm3_insert(Relation rel, Datum *values, bool *isnull,
} }
static IndexScanDesc static IndexScanDesc
lsm3_beginscan(Relation rel, int nkeys, int norderbys) lsm_beginscan(Relation rel, int nkeys, int norderbys)
{ {
IndexScanDesc scan; IndexScanDesc scan;
Lsm3ScanOpaque* so; lsmScanOpaque* so;
int i; int i;
/* no order by operators allowed */ /* no order by operators allowed */
...@@ -519,9 +519,9 @@ lsm3_beginscan(Relation rel, int nkeys, int norderbys) ...@@ -519,9 +519,9 @@ lsm3_beginscan(Relation rel, int nkeys, int norderbys)
/* get the scan */ /* get the scan */
scan = RelationGetIndexScan(rel, nkeys, norderbys); scan = RelationGetIndexScan(rel, nkeys, norderbys);
scan->xs_itupdesc = RelationGetDescr(rel); scan->xs_itupdesc = RelationGetDescr(rel);
so = (Lsm3ScanOpaque*)palloc(sizeof(Lsm3ScanOpaque)); so = (lsmScanOpaque*)palloc(sizeof(lsmScanOpaque));
so->entry = lsm3_get_entry(rel); so->entry = lsm_get_entry(rel);
so->sortKeys = lsm3_build_sortkeys(rel); so->sortKeys = lsm_build_sortkeys(rel);
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
so->top_index[i] = index_open(so->entry->top[i], AccessShareLock); so->top_index[i] = index_open(so->entry->top[i], AccessShareLock);
...@@ -534,7 +534,7 @@ lsm3_beginscan(Relation rel, int nkeys, int norderbys) ...@@ -534,7 +534,7 @@ lsm3_beginscan(Relation rel, int nkeys, int norderbys)
so->scan[i]->xs_want_itup = true; so->scan[i]->xs_want_itup = true;
so->scan[i]->parallel_scan = NULL; so->scan[i]->parallel_scan = NULL;
} }
so->unique = rel->rd_options ? ((Lsm3Options*)rel->rd_options)->unique : false; so->unique = rel->rd_options ? ((lsmOptions*)rel->rd_options)->unique : false;
so->curr_index = -1; so->curr_index = -1;
scan->opaque = so; scan->opaque = so;
...@@ -542,10 +542,10 @@ lsm3_beginscan(Relation rel, int nkeys, int norderbys) ...@@ -542,10 +542,10 @@ lsm3_beginscan(Relation rel, int nkeys, int norderbys)
} }
static void static void
lsm3_rescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, lsm_rescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
ScanKey orderbys, int norderbys) ScanKey orderbys, int norderbys)
{ {
Lsm3ScanOpaque* so = (Lsm3ScanOpaque*) scan->opaque; lsmScanOpaque* so = (lsmScanOpaque*) scan->opaque;
so->curr_index = -1; so->curr_index = -1;
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
...@@ -556,9 +556,9 @@ lsm3_rescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ...@@ -556,9 +556,9 @@ lsm3_rescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
} }
static void static void
lsm3_endscan(IndexScanDesc scan) lsm_endscan(IndexScanDesc scan)
{ {
Lsm3ScanOpaque* so = (Lsm3ScanOpaque*) scan->opaque; lsmScanOpaque* so = (lsmScanOpaque*) scan->opaque;
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
...@@ -573,9 +573,9 @@ lsm3_endscan(IndexScanDesc scan) ...@@ -573,9 +573,9 @@ lsm3_endscan(IndexScanDesc scan)
static bool static bool
lsm3_gettuple(IndexScanDesc scan, ScanDirection dir) lsm_gettuple(IndexScanDesc scan, ScanDirection dir)
{ {
Lsm3ScanOpaque* so = (Lsm3ScanOpaque*) scan->opaque; lsmScanOpaque* so = (lsmScanOpaque*) scan->opaque;
int min = -1; int min = -1;
int curr = so->curr_index; int curr = so->curr_index;
/* We start with active top index, then merging index and last of all: largest base index */ /* We start with active top index, then merging index and last of all: largest base index */
...@@ -603,7 +603,7 @@ lsm3_gettuple(IndexScanDesc scan, ScanDirection dir) ...@@ -603,7 +603,7 @@ lsm3_gettuple(IndexScanDesc scan, ScanDirection dir)
* then we can stop after locating first occurrence. * then we can stop after locating first occurrence.
* If make it possible to avoid lookups of all three indexes. * If make it possible to avoid lookups of all three indexes.
*/ */
elog(DEBUG1, "Lsm3: lookup %d indexes", j+1); elog(DEBUG1, "lsm: lookup %d indexes", j+1);
while (++j < 3) /* prevent search of all remanining indexes */ while (++j < 3) /* prevent search of all remanining indexes */
{ {
so->eof[try_index_order[j]] = true; so->eof[try_index_order[j]] = true;
...@@ -620,7 +620,7 @@ lsm3_gettuple(IndexScanDesc scan, ScanDirection dir) ...@@ -620,7 +620,7 @@ lsm3_gettuple(IndexScanDesc scan, ScanDirection dir)
} }
else else
{ {
int result = lsm3_compare_index_tuples(so->scan[i], so->scan[min], so->sortKeys); int result = lsm_compare_index_tuples(so->scan[i], so->scan[min], so->sortKeys);
if (result == 0) if (result == 0)
{ {
/* Duplicate: it can happen during merge when same tid is both in top and base index */ /* Duplicate: it can happen during merge when same tid is both in top and base index */
...@@ -649,9 +649,9 @@ lsm3_gettuple(IndexScanDesc scan, ScanDirection dir) ...@@ -649,9 +649,9 @@ lsm3_gettuple(IndexScanDesc scan, ScanDirection dir)
} }
static int64 static int64
lsm3_getbitmap(IndexScanDesc scan, TIDBitmap *tbm) lsm_getbitmap(IndexScanDesc scan, TIDBitmap *tbm)
{ {
Lsm3ScanOpaque* so = (Lsm3ScanOpaque*)scan->opaque; lsmScanOpaque* so = (lsmScanOpaque*)scan->opaque;
int64 ntids = 0; int64 ntids = 0;
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
...@@ -662,7 +662,7 @@ lsm3_getbitmap(IndexScanDesc scan, TIDBitmap *tbm) ...@@ -662,7 +662,7 @@ lsm3_getbitmap(IndexScanDesc scan, TIDBitmap *tbm)
} }
Datum Datum
lsm3_handler(PG_FUNCTION_ARGS) lsm_handler(PG_FUNCTION_ARGS)
{ {
IndexAmRoutine *amroutine = makeNode(IndexAmRoutine); IndexAmRoutine *amroutine = makeNode(IndexAmRoutine);
...@@ -686,22 +686,22 @@ lsm3_handler(PG_FUNCTION_ARGS) ...@@ -686,22 +686,22 @@ lsm3_handler(PG_FUNCTION_ARGS)
amroutine->amparallelvacuumoptions = 0; amroutine->amparallelvacuumoptions = 0;
amroutine->amkeytype = InvalidOid; amroutine->amkeytype = InvalidOid;
amroutine->ambuild = lsm3_build; amroutine->ambuild = lsm_build;
amroutine->ambuildempty = btbuildempty; amroutine->ambuildempty = btbuildempty;
amroutine->aminsert = lsm3_insert; amroutine->aminsert = lsm_insert;
amroutine->ambulkdelete = btbulkdelete; amroutine->ambulkdelete = btbulkdelete;
amroutine->amvacuumcleanup = btvacuumcleanup; amroutine->amvacuumcleanup = btvacuumcleanup;
amroutine->amcanreturn = btcanreturn; amroutine->amcanreturn = btcanreturn;
amroutine->amcostestimate = btcostestimate; amroutine->amcostestimate = btcostestimate;
amroutine->amoptions = lsm3_options; amroutine->amoptions = lsm_options;
amroutine->amproperty = btproperty; amroutine->amproperty = btproperty;
amroutine->ambuildphasename = btbuildphasename; amroutine->ambuildphasename = btbuildphasename;
amroutine->amvalidate = btvalidate; amroutine->amvalidate = btvalidate;
amroutine->ambeginscan = lsm3_beginscan; amroutine->ambeginscan = lsm_beginscan;
amroutine->amrescan = lsm3_rescan; amroutine->amrescan = lsm_rescan;
amroutine->amgettuple = lsm3_gettuple; amroutine->amgettuple = lsm_gettuple;
amroutine->amgetbitmap = lsm3_getbitmap; amroutine->amgetbitmap = lsm_getbitmap;
amroutine->amendscan = lsm3_endscan; amroutine->amendscan = lsm_endscan;
amroutine->ammarkpos = NULL; /* When do we need index_markpos? Can we live without it? */ amroutine->ammarkpos = NULL; /* When do we need index_markpos? Can we live without it? */
amroutine->amrestrpos = NULL; amroutine->amrestrpos = NULL;
amroutine->amestimateparallelscan = NULL; amroutine->amestimateparallelscan = NULL;
...@@ -717,7 +717,7 @@ lsm3_handler(PG_FUNCTION_ARGS) ...@@ -717,7 +717,7 @@ lsm3_handler(PG_FUNCTION_ARGS)
/* We do not need to load data in top top index: just initialize index metadata */ /* We do not need to load data in top top index: just initialize index metadata */
static IndexBuildResult * static IndexBuildResult *
lsm3_build_empty(Relation heap, Relation index, IndexInfo *indexInfo) lsm_build_empty(Relation heap, Relation index, IndexInfo *indexInfo)
{ {
Page metapage; Page metapage;
...@@ -752,7 +752,7 @@ lsm3_build_empty(Relation heap, Relation index, IndexInfo *indexInfo) ...@@ -752,7 +752,7 @@ lsm3_build_empty(Relation heap, Relation index, IndexInfo *indexInfo)
} }
static bool static bool
lsm3_dummy_insert(Relation rel, Datum *values, bool *isnull, lsm_dummy_insert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel, ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique, IndexUniqueCheck checkUnique,
IndexInfo *indexInfo) IndexInfo *indexInfo)
...@@ -761,7 +761,7 @@ lsm3_dummy_insert(Relation rel, Datum *values, bool *isnull, ...@@ -761,7 +761,7 @@ lsm3_dummy_insert(Relation rel, Datum *values, bool *isnull,
} }
Datum Datum
lsm3_btree_wrapper(PG_FUNCTION_ARGS) lsm_btree_wrapper(PG_FUNCTION_ARGS)
{ {
IndexAmRoutine *amroutine = makeNode(IndexAmRoutine); IndexAmRoutine *amroutine = makeNode(IndexAmRoutine);
...@@ -785,14 +785,14 @@ lsm3_btree_wrapper(PG_FUNCTION_ARGS) ...@@ -785,14 +785,14 @@ lsm3_btree_wrapper(PG_FUNCTION_ARGS)
amroutine->amparallelvacuumoptions = 0; amroutine->amparallelvacuumoptions = 0;
amroutine->amkeytype = InvalidOid; amroutine->amkeytype = InvalidOid;
amroutine->ambuild = lsm3_build_empty; amroutine->ambuild = lsm_build_empty;
amroutine->ambuildempty = btbuildempty; amroutine->ambuildempty = btbuildempty;
amroutine->aminsert = lsm3_dummy_insert; amroutine->aminsert = lsm_dummy_insert;
amroutine->ambulkdelete = btbulkdelete; amroutine->ambulkdelete = btbulkdelete;
amroutine->amvacuumcleanup = btvacuumcleanup; amroutine->amvacuumcleanup = btvacuumcleanup;
amroutine->amcanreturn = btcanreturn; amroutine->amcanreturn = btcanreturn;
amroutine->amcostestimate = btcostestimate; amroutine->amcostestimate = btcostestimate;
amroutine->amoptions = lsm3_options; amroutine->amoptions = lsm_options;
amroutine->amproperty = btproperty; amroutine->amproperty = btproperty;
amroutine->ambuildphasename = btbuildphasename; amroutine->ambuildphasename = btbuildphasename;
amroutine->amvalidate = btvalidate; amroutine->amvalidate = btvalidate;
...@@ -811,10 +811,10 @@ lsm3_btree_wrapper(PG_FUNCTION_ARGS) ...@@ -811,10 +811,10 @@ lsm3_btree_wrapper(PG_FUNCTION_ARGS)
} }
/* /*
* Utulity hook handling creation of Lsm3 indexes * Utulity hook handling creation of lsm indexes
*/ */
static void static void
lsm3_process_utility(PlannedStmt *plannedStmt, lsm_process_utility(PlannedStmt *plannedStmt,
const char *queryString, const char *queryString,
ProcessUtilityContext context, ProcessUtilityContext context,
ParamListInfo paramListInfo, ParamListInfo paramListInfo,
...@@ -833,7 +833,7 @@ lsm3_process_utility(PlannedStmt *plannedStmt, ...@@ -833,7 +833,7 @@ lsm3_process_utility(PlannedStmt *plannedStmt,
List* drop_oids = NULL; List* drop_oids = NULL;
ListCell* cell; ListCell* cell;
Lsm3Entry = NULL; /* Reset entry to check it after utility statement execution */ lsmEntry = NULL; /* Reset entry to check it after utility statement execution */
if (IsA(parseTree, DropStmt)) if (IsA(parseTree, DropStmt))
{ {
drop = (DropStmt*)parseTree; drop = (DropStmt*)parseTree;
...@@ -843,9 +843,9 @@ lsm3_process_utility(PlannedStmt *plannedStmt, ...@@ -843,9 +843,9 @@ lsm3_process_utility(PlannedStmt *plannedStmt,
{ {
RangeVar* rv = makeRangeVarFromNameList((List *) lfirst(cell)); RangeVar* rv = makeRangeVarFromNameList((List *) lfirst(cell));
Relation index = relation_openrv(rv, ExclusiveLock); Relation index = relation_openrv(rv, ExclusiveLock);
if (index->rd_indam->ambuild == lsm3_build) if (index->rd_indam->ambuild == lsm_build)
{ {
Lsm3DictEntry* entry = lsm3_get_entry(index); lsmDictEntry* entry = lsm_get_entry(index);
if (drop_objects == NULL) if (drop_objects == NULL)
{ {
drop_objects = new_object_addresses(); drop_objects = new_object_addresses();
...@@ -874,9 +874,9 @@ lsm3_process_utility(PlannedStmt *plannedStmt, ...@@ -874,9 +874,9 @@ lsm3_process_utility(PlannedStmt *plannedStmt,
destReceiver, destReceiver,
completionTag); completionTag);
if (Lsm3Entry) if (lsmEntry)
{ {
if (IsA(parseTree, IndexStmt)) /* This is Lsm3 creation statement */ if (IsA(parseTree, IndexStmt)) /* This is lsm creation statement */
{ {
IndexStmt* stmt = (IndexStmt*)parseTree; IndexStmt* stmt = (IndexStmt*)parseTree;
char* originIndexName = stmt->idxname; char* originIndexName = stmt->idxname;
...@@ -888,9 +888,9 @@ lsm3_process_utility(PlannedStmt *plannedStmt, ...@@ -888,9 +888,9 @@ lsm3_process_utility(PlannedStmt *plannedStmt,
{ {
PushActiveSnapshot(GetTransactionSnapshot()); PushActiveSnapshot(GetTransactionSnapshot());
} }
stmt->accessMethod = "lsm3_btree_wrapper"; stmt->accessMethod = "lsm_btree_wrapper";
stmt->idxname = psprintf("%s_top%d", get_rel_name(Lsm3Entry->base), i); stmt->idxname = psprintf("%s_top%d", get_rel_name(lsmEntry->base), i);
Lsm3Entry->top[i] = DefineIndex(Lsm3Entry->heap, lsmEntry->top[i] = DefineIndex(lsmEntry->heap,
stmt, stmt,
InvalidOid, InvalidOid,
InvalidOid, InvalidOid,
...@@ -908,13 +908,13 @@ lsm3_process_utility(PlannedStmt *plannedStmt, ...@@ -908,13 +908,13 @@ lsm3_process_utility(PlannedStmt *plannedStmt,
{ {
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
if (Lsm3Entry->top[i] == InvalidOid) if (lsmEntry->top[i] == InvalidOid)
{ {
char* topidxname = psprintf("%s_top%d", get_rel_name(Lsm3Entry->base), i); char* topidxname = psprintf("%s_top%d", get_rel_name(lsmEntry->base), i);
Lsm3Entry->top[i] = get_relname_relid(topidxname, get_rel_namespace(Lsm3Entry->base)); lsmEntry->top[i] = get_relname_relid(topidxname, get_rel_namespace(lsmEntry->base));
if (Lsm3Entry->top[i] == InvalidOid) if (lsmEntry->top[i] == InvalidOid)
{ {
elog(ERROR, "Lsm3: failed to lookup %s index", topidxname); elog(ERROR, "lsm: failed to lookup %s index", topidxname);
} }
} }
} }
...@@ -928,19 +928,19 @@ lsm3_process_utility(PlannedStmt *plannedStmt, ...@@ -928,19 +928,19 @@ lsm3_process_utility(PlannedStmt *plannedStmt,
/* Mark top index as invalid to prevent planner from using it in queries */ /* Mark top index as invalid to prevent planner from using it in queries */
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
index_set_state_flags(Lsm3Entry->top[i], INDEX_DROP_CLEAR_VALID); index_set_state_flags(lsmEntry->top[i], INDEX_DROP_CLEAR_VALID);
} }
LWLockRelease(Lsm3DictLock); /* Release lock set by lsm3_build */ LWLockRelease(lsmDictLock); /* Release lock set by lsm_build */
} }
else if (drop_objects) else if (drop_objects)
{ {
performMultipleDeletions(drop_objects, drop->behavior, 0); performMultipleDeletions(drop_objects, drop->behavior, 0);
LWLockAcquire(Lsm3DictLock, LW_EXCLUSIVE); LWLockAcquire(lsmDictLock, LW_EXCLUSIVE);
foreach (cell, drop_oids) foreach (cell, drop_oids)
{ {
hash_search(Lsm3Dict, &lfirst_oid(cell), HASH_REMOVE, NULL); hash_search(lsmDict, &lfirst_oid(cell), HASH_REMOVE, NULL);
} }
LWLockRelease(Lsm3DictLock); LWLockRelease(lsmDictLock);
} }
} }
...@@ -949,18 +949,18 @@ lsm3_process_utility(PlannedStmt *plannedStmt, ...@@ -949,18 +949,18 @@ lsm3_process_utility(PlannedStmt *plannedStmt,
* to avoid "you don't own a lock of type RowExclusiveLock" warning * to avoid "you don't own a lock of type RowExclusiveLock" warning
*/ */
static void static void
lsm3_executor_finish(QueryDesc *queryDesc) lsm_executor_finish(QueryDesc *queryDesc)
{ {
if (Lsm3ReleasedLocks) if (lsmReleasedLocks)
{ {
ListCell* cell; ListCell* cell;
foreach (cell, Lsm3ReleasedLocks) foreach (cell, lsmReleasedLocks)
{ {
Oid indexOid = lfirst_oid(cell); Oid indexOid = lfirst_oid(cell);
LockRelationOid(indexOid, RowExclusiveLock); LockRelationOid(indexOid, RowExclusiveLock);
} }
list_free(Lsm3ReleasedLocks); list_free(lsmReleasedLocks);
Lsm3ReleasedLocks = NULL; lsmReleasedLocks = NULL;
} }
if (PreviousExecutorFinish) if (PreviousExecutorFinish)
PreviousExecutorFinish(queryDesc); PreviousExecutorFinish(queryDesc);
...@@ -975,12 +975,12 @@ _PG_init(void) ...@@ -975,12 +975,12 @@ _PG_init(void)
{ {
if (!process_shared_preload_libraries_in_progress) if (!process_shared_preload_libraries_in_progress)
{ {
elog(ERROR, "Lsm3: this extension should be loaded via shared_preload_libraries"); elog(ERROR, "lsm: this extension should be loaded via shared_preload_libraries");
} }
DefineCustomIntVariable("lsm3.top_index_size", DefineCustomIntVariable("lsm.top_index_size",
"Size of top index B-Tree (kb)", "Size of top index B-Tree (kb)",
NULL, NULL,
&Lsm3TopIndexSize, &lsmTopIndexSize,
64*1024, 64*1024,
BLCKSZ/1024, BLCKSZ/1024,
INT_MAX, INT_MAX,
...@@ -990,10 +990,10 @@ _PG_init(void) ...@@ -990,10 +990,10 @@ _PG_init(void)
NULL, NULL,
NULL); NULL);
DefineCustomIntVariable("lsm3.max_indexes", DefineCustomIntVariable("lsm.max_indexes",
"Maximal number of Lsm3 indexes.", "Maximal number of lsm indexes.",
NULL, NULL,
&Lsm3MaxIndexes, &lsmMaxIndexes,
1024, 1024,
1, 1,
INT_MAX, INT_MAX,
...@@ -1003,35 +1003,35 @@ _PG_init(void) ...@@ -1003,35 +1003,35 @@ _PG_init(void)
NULL, NULL,
NULL); NULL);
Lsm3ReloptKind = add_reloption_kind(); lsmReloptKind = add_reloption_kind();
add_bool_reloption(Lsm3ReloptKind, "unique", add_bool_reloption(lsmReloptKind, "unique",
"Index contains no duplicates", "Index contains no duplicates",
false, AccessExclusiveLock); false, AccessExclusiveLock);
add_int_reloption(Lsm3ReloptKind, "top_index_size", add_int_reloption(lsmReloptKind, "top_index_size",
"Size of top index (kb)", "Size of top index (kb)",
0, 0, INT_MAX, AccessExclusiveLock); 0, 0, INT_MAX, AccessExclusiveLock);
add_int_reloption(Lsm3ReloptKind, "fillfactor", add_int_reloption(lsmReloptKind, "fillfactor",
"Packs btree index pages only to this percentage", "Packs btree index pages only to this percentage",
BTREE_DEFAULT_FILLFACTOR, BTREE_MIN_FILLFACTOR, 100, ShareUpdateExclusiveLock); BTREE_DEFAULT_FILLFACTOR, BTREE_MIN_FILLFACTOR, 100, ShareUpdateExclusiveLock);
add_real_reloption(Lsm3ReloptKind, "vacuum_cleanup_index_scale_factor", add_real_reloption(lsmReloptKind, "vacuum_cleanup_index_scale_factor",
"Packs btree index pages only to this percentage", "Packs btree index pages only to this percentage",
-1, 0.0, 1e10, ShareUpdateExclusiveLock); -1, 0.0, 1e10, ShareUpdateExclusiveLock);
add_bool_reloption(Lsm3ReloptKind, "deduplicate_items", add_bool_reloption(lsmReloptKind, "deduplicate_items",
"Enables \"deduplicate items\" feature for this btree index", "Enables \"deduplicate items\" feature for this btree index",
true, AccessExclusiveLock); true, AccessExclusiveLock);
RequestAddinShmemSpace(hash_estimate_size(Lsm3MaxIndexes, sizeof(Lsm3DictEntry))); RequestAddinShmemSpace(hash_estimate_size(lsmMaxIndexes, sizeof(lsmDictEntry)));
RequestNamedLWLockTranche("lsm3", 1); RequestNamedLWLockTranche("lsm", 1);
PreviousShmemStartupHook = shmem_startup_hook; PreviousShmemStartupHook = shmem_startup_hook;
shmem_startup_hook = lsm3_shmem_startup; shmem_startup_hook = lsm_shmem_startup;
PreviousProcessUtilityHook = ProcessUtility_hook; PreviousProcessUtilityHook = ProcessUtility_hook;
ProcessUtility_hook = lsm3_process_utility; ProcessUtility_hook = lsm_process_utility;
PreviousExecutorFinish = ExecutorFinish_hook; PreviousExecutorFinish = ExecutorFinish_hook;
ExecutorFinish_hook = lsm3_executor_finish; ExecutorFinish_hook = lsm_executor_finish;
} }
void _PG_fini(void) void _PG_fini(void)
...@@ -1041,11 +1041,11 @@ void _PG_fini(void) ...@@ -1041,11 +1041,11 @@ void _PG_fini(void)
} }
Datum Datum
lsm3_get_merge_count(PG_FUNCTION_ARGS) lsm_get_merge_count(PG_FUNCTION_ARGS)
{ {
Oid relid = PG_GETARG_OID(0); Oid relid = PG_GETARG_OID(0);
Relation index = index_open(relid, AccessShareLock); Relation index = index_open(relid, AccessShareLock);
Lsm3DictEntry* entry = lsm3_get_entry(index); lsmDictEntry* entry = lsm_get_entry(index);
index_close(index, AccessShareLock); index_close(index, AccessShareLock);
if (entry == NULL) if (entry == NULL)
PG_RETURN_NULL(); PG_RETURN_NULL();
...@@ -1055,11 +1055,11 @@ lsm3_get_merge_count(PG_FUNCTION_ARGS) ...@@ -1055,11 +1055,11 @@ lsm3_get_merge_count(PG_FUNCTION_ARGS)
Datum Datum
lsm3_start_merge(PG_FUNCTION_ARGS) lsm_start_merge(PG_FUNCTION_ARGS)
{ {
Oid relid = PG_GETARG_OID(0); Oid relid = PG_GETARG_OID(0);
Relation index = index_open(relid, AccessShareLock); Relation index = index_open(relid, AccessShareLock);
Lsm3DictEntry* entry = lsm3_get_entry(index); lsmDictEntry* entry = lsm_get_entry(index);
index_close(index, AccessShareLock); index_close(index, AccessShareLock);
SpinLockAcquire(&entry->spinlock); SpinLockAcquire(&entry->spinlock);
...@@ -1073,7 +1073,7 @@ lsm3_start_merge(PG_FUNCTION_ARGS) ...@@ -1073,7 +1073,7 @@ lsm3_start_merge(PG_FUNCTION_ARGS)
entry->start_merge = true; entry->start_merge = true;
if (entry->merger == NULL) /* lazy start of bgworker */ if (entry->merger == NULL) /* lazy start of bgworker */
{ {
lsm3_launch_bgworker(entry); lsm_launch_bgworker(entry);
} }
SetLatch(&entry->merger->procLatch); SetLatch(&entry->merger->procLatch);
} }
...@@ -1083,11 +1083,11 @@ lsm3_start_merge(PG_FUNCTION_ARGS) ...@@ -1083,11 +1083,11 @@ lsm3_start_merge(PG_FUNCTION_ARGS)
} }
Datum Datum
lsm3_wait_merge_completion(PG_FUNCTION_ARGS) lsm_wait_merge_completion(PG_FUNCTION_ARGS)
{ {
Oid relid = PG_GETARG_OID(0); Oid relid = PG_GETARG_OID(0);
Relation index = index_open(relid, AccessShareLock); Relation index = index_open(relid, AccessShareLock);
Lsm3DictEntry* entry = lsm3_get_entry(index); lsmDictEntry* entry = lsm_get_entry(index);
index_close(index, AccessShareLock); index_close(index, AccessShareLock);
while (entry->merge_in_progress) while (entry->merge_in_progress)
...@@ -1098,11 +1098,11 @@ lsm3_wait_merge_completion(PG_FUNCTION_ARGS) ...@@ -1098,11 +1098,11 @@ lsm3_wait_merge_completion(PG_FUNCTION_ARGS)
} }
Datum Datum
lsm3_top_index_size(PG_FUNCTION_ARGS) lsm_top_index_size(PG_FUNCTION_ARGS)
{ {
Oid relid = PG_GETARG_OID(0); Oid relid = PG_GETARG_OID(0);
Relation index = index_open(relid, AccessShareLock); Relation index = index_open(relid, AccessShareLock);
Lsm3DictEntry* entry = lsm3_get_entry(index); lsmDictEntry* entry = lsm_get_entry(index);
index_close(index, AccessShareLock); index_close(index, AccessShareLock);
PG_RETURN_INT64((uint64)lsm3_get_index_size(lsm3_get_index_size(entry->top[entry->active_index]))*BLCKSZ); PG_RETURN_INT64((uint64)lsm_get_index_size(lsm_get_index_size(entry->top[entry->active_index]))*BLCKSZ);
} }
shared_preload_libraries = 'lsm'
lsm.top_index_size=1MB
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment