!1028 小型化裁剪,增强可配置性

Merge pull request !1028 from 苏梓鑫/config
This commit is contained in:
opengauss-bot 2021-07-09 02:24:38 +00:00 committed by Gitee
commit 97a744de3b
48 changed files with 430 additions and 89 deletions

9
configure vendored
View File

@ -2869,6 +2869,14 @@ if test "${enable_mot+set}" = set; then
$as_echo "$as_me: error: --enable-mot option is not supported with --enable-multiple-nodes option" >&2;}
{ (exit 1); exit 1; }; }
fi
if test "$enable_llvm" = no; then
{ { $as_echo "$as_me:$LINENO: error: --enable-mot option is not supported with --disable-llvm option" >&5
$as_echo "$as_me: error: --enable-mot option is not supported with --disable-llvm option" >&2;}
{ (exit 1); exit 1; }; }
fi
;;
no)
@ -5774,6 +5782,7 @@ else
cat >>confdefs.h <<\_ACEOF
#define ENABLE_LLVM_COMPILE 1
_ACEOF
enable_llvm=yes
fi

View File

@ -1434,6 +1434,7 @@ static void HdfsEndForeignScan(ForeignScanState* scanState)
}
}
#ifdef ENABLE_LLVM_COMPILE
/*
* LLVM optimization information should be shown. We check the query
* uses LLVM optimization or not.
@ -1502,6 +1503,7 @@ static void HdfsEndForeignScan(ForeignScanState* scanState)
}
}
}
#endif
/* clears all file related memory */
if (NULL != executionState->fileReader) {

View File

@ -173,6 +173,7 @@ enable_jemalloc_debug = @enable_jemalloc_debug@
enable_privategauss = @enable_privategauss@
enable_multiple_nodes = @enable_multiple_nodes@
enable_mot = @enable_mot@
enable_llvm = @enable_llvm@
enable_mysql_fdw = @enable_mysql_fdw@
enable_oracle_fdw = @enable_oracle_fdw@
enable_pldebugger = @enable_pldebugger@
@ -506,7 +507,9 @@ LIBLLVM_BIN = $(LIBLLVM_HOME)/bin
LIBLLVM_INCLUDE_PATH = $(LIBLLVM_HOME)/include
LIBLLVM_LIB_PATH = $(LIBLLVM_HOME)/lib
LLVM_CONFIG = $(LIBLLVM_BIN)/llvm-config
LLVM_LIBS = $(shell $(LLVM_CONFIG) --libs)
ifeq ($(enable_llvm), yes)
LLVM_LIBS = $(shell $(LLVM_CONFIG) --libs)
endif
#############################################################################
# event component
@ -753,6 +756,10 @@ ifeq ($(enable_mot), yes)
override CPPFLAGS := $(CPPFLAGS) -I$(MASSTREE_INCLUDE_PATH)
endif
ifeq ($(enable_llvm), yes)
override CPPFLAGS := $(CPPFLAGS) -DENABLE_LLVM_COMPILE
endif
CC = @CC@
GCC = @GCC@
C = gcc

View File

@ -482,6 +482,7 @@ standard_conforming_strings|bool|0,0|NULL|NULL|
standby_shared_buffers_fraction|real|0.1,1|NULL|NULL|
statement_timeout|int|0,2147483647|ms|NULL|
stats_temp_directory|string|0,0|NULL|NULL|
num_internal_lock_partitions|string|0,0|NULL|NULL|
stream_multiple|real|0,1.79769e+308|NULL|NULL|
string_hash_compatible|bool|0,0|NULL|NULL|
enable_slow_query_log|bool|0,0|NULL|NULL|
@ -543,6 +544,7 @@ vacuum_defer_cleanup_age|int64|0,1000000|NULL|NULL|
vacuum_freeze_min_age|int64|0,576460752303423487|NULL|NULL|
vacuum_freeze_table_age|int64|0,576460752303423487|NULL|NULL|
hll_default_expthresh|int64|-1,7|NULL|NULL|
wal_insert_status_entries|int|131072,4194304|NULL|Sets the size of wal insert status array for WAL.|
wal_buffers|int|-1,262144|kB|Every time a transaction is committed, the contents of WAL buffers are written to disk, it is set to a large value will not bring significant performance gains. If you set it to hundreds of megabytes, you may have written to the disk to improve performance on the server a lot of real-time transaction commits. According to experience, the default value is sufficient for most situations.|
wal_keep_segments|int|2,2147483647|NULL| When the server is turned on or archive log recovery from the checkpoint, the number of reserved log files may be larger than the set value wal_keep_segments. If this parameter is set too low, at the time of the transaction log backup requests, the new transaction log may have been produced coverage request fails, disconnect the master and slave relationship.|
wal_level|enum|minimal,archive,hot_standby,logical|NULL|If you need to copy the data stream for WAL log archiving and standby machine. You must be set to the parameter with archive or hot_standby. If this parameter is setted to archive. The hot_standby must be setted to off, otherwise it will cause the database can not be started, at the same time the max_wal_senders must be set at least 1.|

View File

@ -43,6 +43,7 @@
#include "catalog/pgxc_group.h"
#include "catalog/storage_gtt.h"
#include "commands/async.h"
#include "commands/copy.h"
#include "commands/prepare.h"
#include "commands/vacuum.h"
#include "commands/variable.h"
@ -4980,6 +4981,20 @@ static void InitConfigureNamesInt()
NULL,
NULL},
{{"wal_insert_status_entries",
PGC_POSTMASTER,
WAL_SETTINGS,
gettext_noop("Sets the size of wal insert status array for WAL."),
NULL,
},
&g_instance.attr.attr_storage.wal_insert_status_entries,
4194304,
131072,
4194304,
check_wal_insert_status_entries,
NULL,
NULL},
{{"wal_writer_delay",
PGC_SIGHUP,
WAL_SETTINGS,
@ -8560,6 +8575,19 @@ static void InitConfigureNamesString()
check_inplace_upgrade_next_oids,
NULL,
NULL},
{{"num_internal_lock_partitions",
PGC_POSTMASTER,
LOCK_MANAGEMENT,
gettext_noop("num of csnlog clog and locktable lwlock partitions."),
NULL,
GUC_LIST_INPUT | GUC_LIST_QUOTE | GUC_SUPERUSER_ONLY},
&g_instance.attr.attr_storage.num_internal_lock_partitions_str,
"CLOG_PART=256,CSNLOG_PART=512,LOG2_LOCKTABLE_PART=4,TWOPHASE_PART=1",
NULL,
NULL,
NULL},
/* analysis options for dfx */
{{"analysis_options",
PGC_USERSET,
@ -19876,4 +19904,31 @@ bool check_numa_distribute_mode(char** newval, void** extra, GucSource source)
return false;
}
/* Initialize storage critical lwlock partition num */
void InitializeNumLwLockPartitions(void)
{
/* set default values */
SetLWLockPartDefaultNum();
/* Do str copy and remove space. */
char* attr = TrimStr(g_instance.attr.attr_storage.num_internal_lock_partitions_str);
if (attr == NULL || attr[0] == '\0') { /* use default values */
return;
}
const char* pdelimiter = ",";
List *res = NULL;
char* nextToken = NULL;
char* token = strtok_s(attr, pdelimiter, &nextToken);
while (token != NULL) {
res = lappend(res, TrimStr(token));
token = strtok_s(NULL, pdelimiter, &nextToken);
}
pfree(attr);
/* check input string and set lwlock num */
CheckAndSetLWLockPartInfo(res);
/* check range */
CheckLWLockPartNumRange();
list_free_deep(res);
}
#include "guc-file.inc"

View File

@ -471,8 +471,10 @@ void gs_thread_exit(int code)
/* free the locale cache */
freeLocaleCache(true);
#ifdef ENABLE_LLVM_COMPILE
/* release llvm context memory */
CodeGenThreadTearDown();
#endif
CancelAutoAnalyze();

View File

@ -300,8 +300,11 @@ void BootStrapProcessMain(int argc, char* argv[])
/* Acquire configuration parameters, unless inherited from postmaster */
if (!IsUnderPostmaster) {
if (!SelectConfigFiles(userDoption, progName))
if (!SelectConfigFiles(userDoption, progName)) {
proc_exit(1);
}
InitializeNumLwLockPartitions();
}
/* Validate we have been given a reasonable-looking t_thrd.proc_cxt.DataDir */

View File

@ -384,24 +384,6 @@ static RangeVar* InitStatementRel()
return relrv;
}
static bool StrToInt32(const char* s, int *val)
{
int base = 10;
const char* ptr = s;
/* process digits */
while (*ptr != '\0') {
if (isdigit((unsigned char)*ptr) == 0)
return false;
int8 digit = (*ptr++ - '0');
*val = *val * base + digit;
if (*val > PG_INT32_MAX || *val < PG_INT32_MIN) {
return false;
}
}
return true;
}
bool check_statement_retention_time(char** newval, void** extra, GucSource source)
{
/* Do str copy and remove space. */

View File

@ -1781,7 +1781,7 @@ static void asyncQueueAdvanceTail(void)
* SimpleLruTruncate() will ask for AsyncCtlLock but will also release
* the lock again.
*/
SimpleLruTruncate(AsyncCtl, newtailpage, false, NUM_SLRU_DEFAULT_PARTITION);
SimpleLruTruncate(AsyncCtl, newtailpage, NUM_SLRU_DEFAULT_PARTITION);
}
}

View File

@ -7491,6 +7491,25 @@ char* scan_dir(DIR* dir, const char* dirpath, const char* pattern, long* filesiz
return NULL;
}
bool StrToInt32(const char* s, int *val)
{
/* set val to zero */
*val = 0;
int base = 10;
const char* ptr = s;
/* process digits */
while (*ptr != '\0') {
if (isdigit((unsigned char)*ptr) == 0)
return false;
int8 digit = (*ptr++ - '0');
*val = *val * base + digit;
if (*val > PG_INT32_MAX || *val < PG_INT32_MIN) {
return false;
}
}
return true;
}
char* TrimStr(const char* str)
{
if (str == NULL) {

View File

@ -1049,10 +1049,12 @@ int PostmasterMain(int argc, char* argv[])
cJSON_Hooks hooks = {cJSON_internal_malloc, cJSON_internal_free};
cJSON_InitHooks(&hooks);
#ifdef ENABLE_LLVM_COMPILE
/*
* Prepare codegen enviroment.
*/
CodeGenProcessInitialize();
#endif
/* Initialize paths to installation files */
getInstallationPaths(argv[0]);
@ -1386,6 +1388,8 @@ int PostmasterMain(int argc, char* argv[])
ExitPostmaster(0);
}
InitializeNumLwLockPartitions();
noProcLogicTid = GLOBAL_ALL_PROCS;
/* Run as FencedUDF master */
@ -7080,7 +7084,9 @@ void ExitPostmaster(int status)
TermMOT(); /* shutdown memory engine before codegen is destroyed */
#endif
#ifdef ENABLE_LLVM_COMPILE
CodeGenProcessTearDown();
#endif
/* Save llt data to disk before postmaster exit */
#ifdef ENABLE_LLT

View File

@ -103,7 +103,9 @@ int StreamMain()
MemoryContext oldMemory = MemoryContextSwitchTo(
THREAD_GET_MEM_CXT_GROUP(MEMORY_CONTEXT_EXECUTOR));
#ifdef ENABLE_LLVM_COMPILE
CodeGenThreadInitialize();
#endif
(void)MemoryContextSwitchTo(oldMemory);
/* We can now handle ereport(ERROR) */

View File

@ -6978,6 +6978,7 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam
gstrace_exit(GS_TRC_ID_PostgresMain);
proc_exit(1);
}
InitializeNumLwLockPartitions();
}
/* initialize guc variables which need to be sended to stream threads */
@ -7841,7 +7842,9 @@ int PostgresMain(int argc, char* argv[], const char* dbname, const char* usernam
u_sess->attr.attr_sql.explain_allow_multinode = false;
MemoryContext oldMemory =
MemoryContextSwitchTo(THREAD_GET_MEM_CXT_GROUP(MEMORY_CONTEXT_EXECUTOR));
#ifdef ENABLE_LLVM_COMPILE
CodeGenThreadInitialize();
#endif
(void)MemoryContextSwitchTo(oldMemory);
u_sess->exec_cxt.single_shard_stmt = false;
/* Set statement_timestamp */

View File

@ -223,8 +223,8 @@ static void knl_t_shemem_ptr_init(knl_t_shemem_ptr_context* shemem_ptr_cxt)
shemem_ptr_cxt->MultiXactState = NULL;
shemem_ptr_cxt->OldestMemberMXactId = NULL;
shemem_ptr_cxt->OldestVisibleMXactId = NULL;
shemem_ptr_cxt->ClogCtl = (SlruCtlData*)palloc0(NUM_CLOG_PARTITIONS * sizeof(SlruCtlData));
shemem_ptr_cxt->CsnlogCtlPtr = (SlruCtlData*)palloc0(NUM_CSNLOG_PARTITIONS * sizeof(SlruCtlData));
shemem_ptr_cxt->ClogCtl = (SlruCtlData*)palloc0(MAX_NUM_CLOG_PARTITIONS * sizeof(SlruCtlData));
shemem_ptr_cxt->CsnlogCtlPtr = (SlruCtlData*)palloc0(MAX_NUM_CSNLOG_PARTITIONS * sizeof(SlruCtlData));
shemem_ptr_cxt->XLogCtl = NULL;
shemem_ptr_cxt->GlobalWALInsertLocks = NULL;
shemem_ptr_cxt->LocalGroupWALInsertLocks = NULL;

View File

@ -8,6 +8,10 @@ subdir = src/gausskernel/runtime
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
SUBDIRS = codegen executor vecexecutor
SUBDIRS = executor vecexecutor
ifeq ($(enable_llvm), yes)
SUBDIRS += codegen
endif
include $(top_srcdir)/src/gausskernel/common.mk

View File

@ -940,6 +940,7 @@ void CodeGenProcessInitialize()
}
}
/**
* @Description : Clean up LLVM enviroment resource
* before exit postmaster.

View File

@ -307,8 +307,10 @@ void standard_ExecutorStart(QueryDesc *queryDesc, int eflags)
old_context = MemoryContextSwitchTo(estate->es_query_cxt);
#ifdef ENABLE_LLVM_COMPILE
/* Initialize the actual CodeGenObj */
CodeGenThreadRuntimeSetup();
#endif
/*
* Fill in external parameters, if any, from queryDesc; and allocate
@ -550,6 +552,7 @@ void standard_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, long co
*/
old_context = MemoryContextSwitchTo(estate->es_query_cxt);
#ifdef ENABLE_LLVM_COMPILE
/*
* Generate machine code for this query.
*/
@ -562,6 +565,7 @@ void standard_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, long co
CodeGenThreadRuntimeCodeGenerate();
}
}
#endif
/* Allow instrumentation of Executor overall runtime */
if (queryDesc->totaltime) {
@ -772,9 +776,11 @@ void standard_ExecutorEnd(QueryDesc *queryDesc)
UnregisterSnapshot(estate->es_snapshot);
UnregisterSnapshot(estate->es_crosscheck_snapshot);
#ifdef ENABLE_LLVM_COMPILE
if (!t_thrd.codegen_cxt.g_runningInFmgr) {
CodeGenThreadTearDown();
}
#endif
/*
* Must switch out of context before destroying it

View File

@ -727,6 +727,7 @@ VecAggState* ExecInitVecAggregation(VecAgg* node, EState* estate, int eflags)
aggstate->numaggs = aggno + 1;
aggstate->aggRun = NULL;
#ifdef ENABLE_LLVM_COMPILE
/*
* Generate IR function for HashAggRunner::BuildAggTbl function, which
* contains hashing part, allocate hashcell and agg part
@ -741,6 +742,7 @@ VecAggState* ExecInitVecAggregation(VecAgg* node, EState* estate, int eflags)
dorado::VecHashAggCodeGen::HashAggCodeGen(aggstate);
}
}
#endif
return aggstate;
}

View File

@ -677,6 +677,7 @@ CStoreScanState* ExecInitCStoreScan(
InitCStoreRelation(scan_stat, estate, idx_flag, parent_heap_rel);
scan_stat->ps.ps_TupFromTlist = false;
#ifdef ENABLE_LLVM_COMPILE
/*
* First, not only consider the LLVM native object, but also consider the cost of
* the LLVM compilation time. We will not use LLVM optimization if there is
@ -702,6 +703,7 @@ CStoreScanState* ExecInitCStoreScan(
llvm_code_gen->addFunctionToMCJit(jitted_vecqual, reinterpret_cast<void**>(&(scan_stat->jitted_vecqual)));
}
}
#endif
/*
* Initialize result tuple type and projection info.
@ -758,6 +760,7 @@ CStoreScanState* ExecInitCStoreScan(
scan_stat->m_pScanBatch->CreateSysColContainer(CurrentMemoryContext, plan_stat->ps_ProjInfo->pi_sysAttrList);
}
#ifdef ENABLE_LLVM_COMPILE
/**
* Since we separate the target list elements into simple var references and
* generic expression, we only need to deal the generic expression with LLVM
@ -776,6 +779,7 @@ CStoreScanState* ExecInitCStoreScan(
llvm_code_gen->addFunctionToMCJit(
jitted_vectarget, reinterpret_cast<void**>(&(plan_stat->ps_ProjInfo->jitted_vectarget)));
}
#endif
scan_stat->m_pScanRunTimeKeys = NULL;
scan_stat->m_ScanRunTimeKeysNum = 0;

View File

@ -295,6 +295,7 @@ CStoreIndexScanState* ExecInitCstoreIndexScan(CStoreIndexScan* node, EState* est
rc = memcpy_s(indexstate, sizeof(CStoreScanState), scanstate, sizeof(CStoreScanState));
securec_check(rc, "\0", "\0");
#ifdef ENABLE_LLVM_COMPILE
/*
* First, not only consider the LLVM native object, but also consider the cost of
* the LLVM compilation time. We will not use LLVM optimization if there is
@ -315,6 +316,7 @@ CStoreIndexScanState* ExecInitCstoreIndexScan(CStoreIndexScan* node, EState* est
if (jitted_vecqual != NULL)
llvmCodeGen->addFunctionToMCJit(jitted_vecqual, reinterpret_cast<void**>(&(indexstate->jitted_vecqual)));
}
#endif
indexstate->ps.plan = (Plan*)node;
indexstate->ps.state = estate;

View File

@ -170,6 +170,7 @@ VecGroupState* ExecInitVecGroup(VecGroup* node, EState* estate, int eflags)
grp_state->ss.ps.targetlist = (List*)ExecInitVecExpr((Expr*)node->plan.targetlist, (PlanState*)grp_state);
grp_state->ss.ps.qual = (List*)ExecInitVecExpr((Expr*)node->plan.qual, (PlanState*)grp_state);
#ifdef ENABLE_LLVM_COMPILE
/*
* Check if nlstate->js.joinqual and nlstate->js.ps.qual expr list could be
* codegened or not.
@ -184,6 +185,7 @@ VecGroupState* ExecInitVecGroup(VecGroup* node, EState* estate, int eflags)
if (grp_vecqual != NULL)
llvm_code_gen->addFunctionToMCJit(grp_vecqual, reinterpret_cast<void**>(&(grp_state->jitted_vecqual)));
}
#endif
// initialize child nodes
outerPlanState(grp_state) = ExecInitNode(outerPlan(node), estate, eflags);

View File

@ -128,10 +128,12 @@ VecHashJoinState* ExecInitVecHashJoin(VecHashJoin* node, EState* estate, int efl
* Since most of the expression information will be used
* later, we still need to initialize these expression.
*/
#ifdef ENABLE_LLVM_COMPILE
dorado::GsCodeGen* llvmCodeGen = (dorado::GsCodeGen*)t_thrd.codegen_cxt.thr_codegen_obj;
bool consider_codegen =
CodeGenThreadObjectReady() &&
CodeGenPassThreshold(((Plan*)outer_node)->plan_rows, estate->es_plannedstmt->num_nodes, ((Plan*)outer_node)->dop);
#endif
if (hash_state->js.ps.targetlist) {
hash_state->js.ps.ps_ProjInfo = ExecBuildVecProjectionInfo(hash_state->js.ps.targetlist,
@ -140,6 +142,7 @@ VecHashJoinState* ExecInitVecHashJoin(VecHashJoin* node, EState* estate, int efl
hash_state->js.ps.ps_ResultTupleSlot,
NULL);
#ifdef ENABLE_LLVM_COMPILE
bool saved_codegen = consider_codegen;
if (isIntergratedMachine) {
consider_codegen =
@ -169,6 +172,7 @@ VecHashJoinState* ExecInitVecHashJoin(VecHashJoin* node, EState* estate, int efl
}
consider_codegen = saved_codegen;
#endif
ExecAssignVectorForExprEval(hash_state->js.ps.ps_ProjInfo->pi_exprContext);
} else {
@ -210,6 +214,7 @@ VecHashJoinState* ExecInitVecHashJoin(VecHashJoin* node, EState* estate, int efl
hash_state->eqfunctions = eqfunctions;
hash_state->js.ps.ps_TupFromTlist = false;
#ifdef ENABLE_LLVM_COMPILE
/* Initialize runtime bloomfilter. */
hash_state->bf_runtime.bf_var_list = hash_state->js.ps.plan->var_list;
hash_state->bf_runtime.bf_filter_index = hash_state->js.ps.plan->filterIndexList;
@ -221,6 +226,7 @@ VecHashJoinState* ExecInitVecHashJoin(VecHashJoin* node, EState* estate, int efl
if (consider_codegen && !node->isSonicHash) {
dorado::VecHashJoinCodeGen::HashJoinCodeGen(hash_state);
}
#endif
return hash_state;
}

View File

@ -1899,6 +1899,7 @@ VecMergeJoinState* ExecInitVecMergeJoin(VecMergeJoin* node, EState* estate, int
node->mergeNullsFirst,
(PlanState*)mergestate);
#ifdef ENABLE_LLVM_COMPILE
/*
* After all of the expressions have been decided, check if the following
* exprs can be codegened or not.
@ -1922,6 +1923,7 @@ VecMergeJoinState* ExecInitVecMergeJoin(VecMergeJoin* node, EState* estate, int
jitted_vectarget, reinterpret_cast<void**>(&(mergestate->js.ps.ps_ProjInfo->jitted_vectarget)));
}
}
#endif
for (i = 0; i < mergestate->mj_NumClauses; i++) {
VecMergeJoinClause clause = &mergestate->mj_Clauses[i];

View File

@ -473,6 +473,7 @@ VecNestLoopState* ExecInitVecNestLoop(VecNestLoop* node, EState* estate, int efl
nlstate->js.joinqual = (List*)ExecInitVecExpr((Expr*)node->join.joinqual, (PlanState*)nlstate);
Assert(node->join.nulleqqual == NIL);
#ifdef ENABLE_LLVM_COMPILE
/*
* Check if nlstate->js.joinqual and nlstate->js.ps.qual expr list could be
* codegened or not.
@ -492,6 +493,7 @@ VecNestLoopState* ExecInitVecNestLoop(VecNestLoop* node, EState* estate, int efl
if (nl_joinqual != NULL)
llvm_code_gen->addFunctionToMCJit(nl_joinqual, reinterpret_cast<void**>(&(nlstate->jitted_joinqual)));
}
#endif
/*
* initialize child nodes

View File

@ -331,6 +331,7 @@ VecSortState* ExecInitVecSort(Sort* node, EState* estate, int eflags)
SO1_printf("ExecInitVecSort: %s\n", "sort node initialized");
#ifdef ENABLE_LLVM_COMPILE
/*
* Consider codegeneration for sort node. In fact, CompareMultiColumn is the
* hotest function in sort node.
@ -363,6 +364,7 @@ VecSortState* ExecInitVecSort(Sort* node, EState* estate, int eflags)
}
}
}
#endif
return sort_stat;
}

View File

@ -141,11 +141,12 @@ bool HdfsScanPredicate<T, baseType>::BuildHdfsScanPredicateFromClause(Expr *expr
return runningTimeSet;
}
#ifdef ENABLE_LLVM_COMPILE
/* Build IR according to expr node. */
if (CodeGenThreadObjectReady()) {
(void)ForeignScanExprCodeGen(expr, NULL, &m_jittedFunc);
}
#endif
if (IsA(rightop, Const)) {
datumValue = ((Const *)rightop)->constvalue;
datumType = ((Const *)rightop)->consttype;

View File

@ -1050,7 +1050,7 @@ void TruncateCLOG(TransactionId oldestXact)
WriteTruncateXlogRec(cutoffPage);
/* Now we can remove the old CLOG segment(s) */
SimpleLruTruncate(ClogCtl(0), cutoffPage, true, NUM_CLOG_PARTITIONS);
SimpleLruTruncate(ClogCtl(0), cutoffPage, NUM_CLOG_PARTITIONS);
ereport(LOG, (errmsg("Truncate CLOG at xid %lu", oldestXact)));
}
@ -1118,7 +1118,7 @@ void clog_redo(XLogReaderState *record)
*/
ClogCtl(pageno)->shared->latest_page_number = pageno;
SimpleLruTruncate(ClogCtl(0), pageno, true, NUM_CLOG_PARTITIONS);
SimpleLruTruncate(ClogCtl(0), pageno, NUM_CLOG_PARTITIONS);
} else
ereport(PANIC, (errmsg("clog_redo: unknown op code %u", (uint32)info)));
}

View File

@ -883,7 +883,7 @@ void TruncateCSNLOG(TransactionId oldestXact)
*/
cutoffPage = TransactionIdToCSNPage(oldestXact);
SimpleLruTruncate(CsnlogCtl(0), cutoffPage, true, NUM_CSNLOG_PARTITIONS);
SimpleLruTruncate(CsnlogCtl(0), cutoffPage, NUM_CSNLOG_PARTITIONS);
elog(LOG, "truncate CSN log oldestXact %lu, next xid %lu", oldestXact, t_thrd.xact_cxt.ShmemVariableCache->nextXid);
}

View File

@ -1738,14 +1738,14 @@ static void TruncateMultiXact(void)
*/
cutoffPage = (int)MultiXactIdToOffsetPage(oldestMXact);
SimpleLruTruncate(t_thrd.shemem_ptr_cxt.MultiXactOffsetCtl, cutoffPage, false, NUM_SLRU_DEFAULT_PARTITION);
SimpleLruTruncate(t_thrd.shemem_ptr_cxt.MultiXactOffsetCtl, cutoffPage, NUM_SLRU_DEFAULT_PARTITION);
/*
* Also truncate MultiXactMember at the previously determined offset.
*/
cutoffPage = (int)MXOffsetToMemberPage(oldestOffset);
SimpleLruTruncate(t_thrd.shemem_ptr_cxt.MultiXactMemberCtl, cutoffPage, false, NUM_SLRU_DEFAULT_PARTITION);
SimpleLruTruncate(t_thrd.shemem_ptr_cxt.MultiXactMemberCtl, cutoffPage, NUM_SLRU_DEFAULT_PARTITION);
/*
* Set the last known truncation point. We don't need a lock for this

View File

@ -1076,11 +1076,12 @@ int SimpleLruFlush(SlruCtl ctl, bool checkpoint)
/*
* Remove all segments before the one holding the passed page number
*/
void SimpleLruTruncate(SlruCtl ctl, int64 cutoffPage, bool isPart, int partitionNum)
void SimpleLruTruncate(SlruCtl ctl, int64 cutoffPage, int partitionNum)
{
SlruShared shared = NULL;
int64 slotno;
bool isCsnLogCtl = strcmp(ctl->dir, "pg_csnlog") == 0;
bool isPart = (partitionNum > NUM_SLRU_DEFAULT_PARTITION);
/*
* The cutoff point is the start of the segment containing cutoffPage.

View File

@ -3816,6 +3816,7 @@ static void AbortTransaction(bool PerfectRollback, bool STP_rollback)
}
}
#ifdef ENABLE_LLVM_COMPILE
/*
* @llvm
* when the query is abnormal exited, the (GsCodeGen *)t_thrd.codegen_cxt.thr_codegen_obj->codeGenState
@ -3824,6 +3825,7 @@ static void AbortTransaction(bool PerfectRollback, bool STP_rollback)
* function.
*/
CodeGenThreadTearDown();
#endif
CancelAutoAnalyze();
lightProxy::setCurrentProxy(NULL);
@ -6438,8 +6440,10 @@ void AbortSubTransaction(bool STP_rollback)
delete_ec_ctrl();
#endif
#ifdef ENABLE_LLVM_COMPILE
/* reset machine code */
CodeGenThreadReset();
#endif
/* Reset the compatible illegal chars import flag */
u_sess->mb_cxt.insertValuesBind_compatible_illegal_chars = false;

View File

@ -6648,6 +6648,27 @@ bool check_wal_buffers(int *newval, void **extra, GucSource source)
return true;
}
/*
* GUC check_hook for wal_insert_status_entries
*/
bool check_wal_insert_status_entries(int *newval, void **extra, GucSource source)
{
// if newval not power of 2
if (!((*newval != 0) && ((*newval & (*newval - 1)) == 0))) {
// get next Power Of 2 form newval
unsigned count = 0;
unsigned n = *newval;
while( n != 0)
{
n >>= 1;
count += 1;
}
*newval = 1 << count;
}
return true;
}
/*
* Initialization of shared memory for XLOG
*/

View File

@ -76,6 +76,7 @@
#include "access/multixact.h"
#include "access/subtrans.h"
#include "commands/async.h"
#include "commands/copy.h"
#include "lib/ilist.h"
#include "miscadmin.h"
#include "pg_trace.h"
@ -90,6 +91,7 @@
#include "storage/spin.h"
#include "storage/cucache_mgr.h"
#include "utils/atomic.h"
#include "utils/builtins.h"
#include "instruments/instr_event.h"
#include "instruments/instr_statement.h"
#include "tsan_annotation.h"
@ -137,12 +139,17 @@ static const char *BuiltinTrancheNames[] = {
"UniqueSQLMappingLock",
"InstrUserLockId",
"GPCMappingLock",
"GPCPrepareMappingLock",
"UspagrpMappingLock",
"ProcXactMappingLock",
"ASPMappingLock",
"GlobalSeqLock",
"GlobalWorkloadLock",
"NormalizedSqlLock",
"StartBlockMappingLock",
"BufferIOLock",
"BufferContentLock",
"UndoPerZoneLock",
"UndoSpaceLock",
"DataCacheLock",
"MetaCacheLock",
"PGPROCLock",
@ -169,7 +176,9 @@ static const char *BuiltinTrancheNames[] = {
"IOStatLock",
"WALFlushWait",
"WALBufferInitWait",
"WALInitSegment"
"WALInitSegment",
"SegmentHeadPartitionLock",
"TwoPhaseStatePartLock"
};
static void RegisterLWLockTranches(void);
@ -539,10 +548,6 @@ static void InitializeLWLocks(int numLocks)
LWLockInitialize(&lock->lock, LWTRANCHE_GPC_MAPPING);
}
for (id = 0; id < NUM_GPC_PARTITIONS; id++, lock++) {
LWLockInitialize(&lock->lock, LWTRANCHE_GPC_PREPARE_MAPPING);
}
for (id = 0; id < NUM_UNIQUE_SQL_PARTITIONS; id++, lock++) {
LWLockInitialize(&lock->lock, LWTRANCHE_ASP_MAPPING);
}
@ -551,6 +556,10 @@ static void InitializeLWLocks(int numLocks)
LWLockInitialize(&lock->lock, LWTRANCHE_GlobalSeq);
}
for (id = 0; id < NUM_GWC_PARTITIONS; id++, lock++) {
LWLockInitialize(&lock->lock, LWTRANCHE_GWC_MAPPING);
}
for (id = 0; id < NUM_NORMALIZED_SQL_PARTITIONS; id++, lock++) {
LWLockInitialize(&lock->lock, LWTRANCHE_NORMALIZED_SQL);
}
@ -567,6 +576,22 @@ static void InitializeLWLocks(int numLocks)
LWLockInitialize(&lock->lock, LWTRANCHE_IO_STAT);
}
for (id = 0; id < NUM_PROCXACT_PARTITIONS; id++, lock++) {
LWLockInitialize(&lock->lock, LWTRANCHE_PROC_XACT_MAPPING);
}
for (id = 0; id < NUM_STARTBLOCK_PARTITIONS; id++, lock++) {
LWLockInitialize(&lock->lock, LWTRANCHE_START_BLOCK_MAPPING);
}
for (id = 0; id < NUM_TWOPHASE_PARTITIONS; id++, lock++) {
LWLockInitialize(&lock->lock, LWTRANCHE_TWOPHASE_STATE);
}
for (id = 0; id < NUM_SEGMENT_HEAD_PARTITIONS; id++, lock++) {
LWLockInitialize(&lock->lock, LWTRANCHE_SEGHEAD_PARTITION);
}
Assert((lock - t_thrd.shemem_ptr_cxt.mainLWLockArray) == NumFixedLWLocks);
for (id = NumFixedLWLocks; id < numLocks; id++, lock++) {
@ -2035,3 +2060,87 @@ LWLockMode GetHeldLWLockMode(LWLock *lock)
return (LWLockMode)0; /* keep compiler silence */
}
static int FindLWLockPartIndex(const char* name)
{
int i;
for (i = 0; i < LWLOCK_PART_KIND; i++) {
if (pg_strcasecmp(name, LWLockPartInfo[i].name) == 0) {
return i;
}
}
return -1;
}
static bool CheckAndSetLWLockPartNum(const char* input)
{
const int pairNum = 2;
/* Do str copy and remove space. */
char* strs = TrimStr(input);
if (strs == NULL || strs[0] == '\0') {
return false;
}
const char* delim = "=";
List *res = NULL;
char* nextToken = NULL;
/* Get name and num */
char* token = strtok_s(strs, delim, &nextToken);
while (token != NULL) {
res = lappend(res, TrimStr(token));
token = strtok_s(NULL, delim, &nextToken);
}
pfree(strs);
if (res->length != pairNum) {
list_free_deep(res);
return false;
}
int index = FindLWLockPartIndex((char*)linitial(res));
if (index != -1) {
if (!StrToInt32((char*)lsecond(res), &g_instance.attr.attr_storage.num_internal_lock_partitions[index])) {
ereport(FATAL, (errcode(ERRCODE_OPERATE_INVALID_PARAM),
errmsg("num_internal_lock_partitions attr has invalid lwlock num:%s.", (char*)lsecond(res))));
}
list_free_deep(res);
return true;
} else {
ereport(FATAL, (errcode(ERRCODE_OPERATE_INVALID_PARAM),
errmsg("num_internal_lock_partitions attr has invalid lwlock name: %s.", (char*)linitial(res))));
return false; /* keep compiler silence */
}
}
void SetLWLockPartDefaultNum(void)
{
int i;
for (i = 0; i < LWLOCK_PART_KIND; i++) {
g_instance.attr.attr_storage.num_internal_lock_partitions[i] = LWLockPartInfo[i].defaultNumPartition;
}
}
void CheckAndSetLWLockPartInfo(const List* res)
{
ListCell* cell = NULL;
foreach (cell, res) {
char* input = (char*)lfirst(cell);
if (!CheckAndSetLWLockPartNum(input)) {
ereport(FATAL, (errcode(ERRCODE_OPERATE_INVALID_PARAM),
errmsg("num_internal_lock_partitions attr has invalid input syntax.")));
}
}
}
void CheckLWLockPartNumRange(void)
{
int i;
for (i = 0; i < LWLOCK_PART_KIND; i++) {
if (g_instance.attr.attr_storage.num_internal_lock_partitions[i] < LWLockPartInfo[i].minNumPartition ||
g_instance.attr.attr_storage.num_internal_lock_partitions[i] > LWLockPartInfo[i].maxNumPartition) {
ereport(FATAL, (errcode(ERRCODE_OPERATE_INVALID_PARAM),
errmsg("Invalid attribute for internal lock partitions."),
errdetail("Current %s lock partition num %d is out of range [%d, %d].",
LWLockPartInfo[i].name, g_instance.attr.attr_storage.num_internal_lock_partitions[i],
LWLockPartInfo[i].minNumPartition, LWLockPartInfo[i].maxNumPartition)));
}
}
}

View File

@ -891,7 +891,7 @@ void CheckPointPredicate(void)
LWLockRelease(OldSerXidLock);
/* Truncate away pages that are no longer required */
SimpleLruTruncate(t_thrd.shemem_ptr_cxt.OldSerXidSlruCtl, tailPage, false, NUM_SLRU_DEFAULT_PARTITION);
SimpleLruTruncate(t_thrd.shemem_ptr_cxt.OldSerXidSlruCtl, tailPage, NUM_SLRU_DEFAULT_PARTITION);
/*
* Flush dirty SLRU pages to disk

View File

@ -277,6 +277,8 @@ void InitProcGlobal(void)
PGPROC *initProcs[MAX_NUMA_NODE] = {0};
int nNumaNodes = g_instance.shmem_cxt.numaNodeNum;
/* since myProcLocks is a various array, need palloc actrual size */
Size actrualPgProcSize = offsetof(PGPROC, myProcLocks) + NUM_LOCK_PARTITIONS * sizeof(SHM_QUEUE);
#ifdef __USE_NUMA
if (nNumaNodes > 1) {
ereport(INFO, (errmsg("InitProcGlobal nNumaNodes: %d, inheritThreadPool: %d, groupNum: %d",
@ -284,7 +286,7 @@ void InitProcGlobal(void)
(g_threadPoolControler ? g_threadPoolControler->GetGroupNum() : 0))));
int groupProcCount = (TotalProcs + nNumaNodes - 1) / nNumaNodes;
size_t allocSize = groupProcCount * sizeof(PGPROC);
size_t allocSize = groupProcCount * actrualPgProcSize;
for (int nodeNo = 0; nodeNo < nNumaNodes; nodeNo++) {
initProcs[nodeNo] = (PGPROC *)numa_alloc_onnode(allocSize, nodeNo);
if (!initProcs[nodeNo]) {
@ -292,13 +294,13 @@ void InitProcGlobal(void)
errmsg("InitProcGlobal NUMA memory allocation in node %d failed.", nodeNo)));
}
add_numa_alloc_info(initProcs[nodeNo], allocSize);
int ret = memset_s(initProcs[nodeNo], groupProcCount * sizeof(PGPROC), 0, groupProcCount * sizeof(PGPROC));
int ret = memset_s(initProcs[nodeNo], allocSize, 0, allocSize);
securec_check_c(ret, "\0", "\0");
}
} else {
#endif
if (needPalloc) {
initProcs[0] = (PGPROC *)CACHELINEALIGN(palloc0(TotalProcs * sizeof(PGPROC) + PG_CACHE_LINE_SIZE));
initProcs[0] = (PGPROC *)CACHELINEALIGN(palloc0(TotalProcs * actrualPgProcSize + PG_CACHE_LINE_SIZE));
} else {
initProcs[0] = g_instance.proc_base->allProcs[0];
errno_t rc = memset_s(initProcs[0], TotalProcs * sizeof(PGPROC), 0, TotalProcs * sizeof(PGPROC));
@ -326,8 +328,8 @@ void InitProcGlobal(void)
if (procs == NULL)
ereport(FATAL, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of shared memory")));
for (i = 0; (unsigned int)(i) < TotalProcs; i++) {
procs[i] = &initProcs[i % nNumaNodes][i / nNumaNodes];
for (i = 0; (unsigned int)(i) < TotalProcs; i++) { /* set proc pointer to actural position */
procs[i] = (PGPROC *)((char*)(initProcs[i % nNumaNodes]) + (i / nNumaNodes) * actrualPgProcSize);
}
if (needPalloc) {

View File

@ -154,7 +154,7 @@ extern int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int64 pageno, TransactionId x
extern int SimpleLruReadPage_ReadOnly_Locked(SlruCtl ctl, int64 pageno, TransactionId xid);
extern void SimpleLruWritePage(SlruCtl ctl, int slotno);
extern int SimpleLruFlush(SlruCtl ctl, bool checkpoint);
extern void SimpleLruTruncate(SlruCtl ctl, int64 cutoffPage, bool isPart, int partitionNum);
extern void SimpleLruTruncate(SlruCtl ctl, int64 cutoffPage, int partitionNum);
typedef bool (*SlruScanCallback)(SlruCtl ctl, const char* filename, int64 segpage, const void* data);
extern bool SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, const void* data);

View File

@ -151,7 +151,7 @@ typedef struct {
PGSemaphoreData sem;
} WALBufferInitWaitLock;
#define WAL_INSERT_STATUS_ENTRIES 4194304
#define WAL_INSERT_STATUS_ENTRIES g_instance.attr.attr_storage.wal_insert_status_entries
#define WAL_NOT_COPIED 0
#define WAL_COPIED 1
#define WAL_COPY_SUSPEND (-1)

View File

@ -32,7 +32,7 @@
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#ifdef ENABLE_LLVM_COMPILE
#include "llvm/IR/Verifier.h"
#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/ExecutionEngine/ObjectCache.h"
@ -53,6 +53,7 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/raw_os_ostream.h"
#endif
#undef __STDC_LIMIT_MACROS
#include "c.h"
@ -155,6 +156,7 @@ const int llvm_smul_with_overflow = 236;
const int llvm_ssub_with_overflow = 241;
#ifdef ENABLE_LLVM_COMPILE
/*
* Declare related LLVM classes to avoid namespace pollution.
*/
@ -181,6 +183,7 @@ class IRBuilder;
class IRBuilderDefaultInserter;
} // namespace llvm
#endif
namespace dorado {
@ -196,6 +199,7 @@ bool canInitCodegenInvironment();
*/
bool canInitThreadCodeGen();
#ifdef ENABLE_LLVM_COMPILE
class GsCodeGen : public BaseObject {
public:
void initialize();
@ -583,6 +587,7 @@ private:
/* Records the c-function calls in codegen IR fucntion of expression tree */
List* m_cfunction_calls;
};
#endif
/*
* Macros used to define the variables

View File

@ -33,6 +33,7 @@
#include "codegen/gscodegen.h"
namespace dorado {
#ifdef ENABLE_LLVM_COMPILE
/*
* @Description : Arguments used for Vectorized Expression CodeGen Engine.
*/
@ -464,5 +465,6 @@ public:
*/
static llvm::Value* MemCxtSwitToCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* context);
};
#endif
} // namespace dorado
#endif

View File

@ -36,6 +36,7 @@ namespace dorado {
/*
* VecHashAggCodeGen class implements specific optimization by using LLVM
*/
#ifdef ENABLE_LLVM_COMPILE
class VecHashAggCodeGen : public BaseObject {
public:
/*
@ -225,6 +226,7 @@ public:
*/
static void WrapResetEContextCodeGen(GsCodeGen::LlvmBuilder* ptrbuilder, llvm::Value* econtext);
};
#endif
} // namespace dorado
#endif

View File

@ -38,6 +38,7 @@ namespace dorado {
/*
* VecHashJoinCodeGen class implements specific optimization by using LLVM
*/
#ifdef ENABLE_LLVM_COMPILE
class VecHashJoinCodeGen : public BaseObject {
public:
/*
@ -168,5 +169,6 @@ public:
*/
static llvm::Function* HashJoinCodeGen_bf_includeLong(VecHashJoinState* node);
};
#endif
} // namespace dorado
#endif

View File

@ -39,6 +39,7 @@ namespace dorado {
/*
* VecSortCodeGen class implements specific optimization by using LLVM
*/
#ifdef ENABLE_LLVM_COMPILE
class VecSortCodeGen : public BaseObject {
public:
/*
@ -151,5 +152,6 @@ public:
*/
static llvm::Function* SortAggTexteqCodeGen();
};
#endif
} // namespace dorado
#endif

View File

@ -378,6 +378,7 @@ extern bool IsCharType(Oid attr_type);
extern int GetDecimalFromHex(char hex);
extern char* limit_printout_length(const char* str);
extern bool StrToInt32(const char* s, int *val);
extern char* TrimStr(const char* str);
#endif /* COPY_H */

View File

@ -40,6 +40,15 @@
#include "knl/knl_guc/knl_guc_common.h"
/* order should same as lwlock part num desc, see lwlock.h */
enum LWLOCK_PARTITION_ID {
CLOG_PART = 0,
CSNLOG_PART = 1,
LOG2_LOCKTABLE_PART = 2,
TWOPHASE_PART = 3,
LWLOCK_PART_KIND
};
typedef struct knl_instance_attr_storage {
bool wal_log_hints;
bool EnableHotStandby;
@ -66,6 +75,7 @@ typedef struct knl_instance_attr_storage {
int wal_writer_cpu;
int wal_file_init_num;
int XLOGbuffers;
int wal_insert_status_entries;
int max_wal_senders;
int max_replication_slots;
int replication_type;
@ -95,6 +105,8 @@ typedef struct knl_instance_attr_storage {
int max_concurrent_autonomous_transactions;
#endif
char* available_zone;
int num_internal_lock_partitions[LWLOCK_PART_KIND];
char* num_internal_lock_partitions_str;
} knl_instance_attr_storage;
#endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_STORAGE_H_ */

View File

@ -15,6 +15,7 @@
#define LWLOCK_H
#include "lib/ilist.h"
#include "nodes/pg_list.h"
#include "storage/lock/s_lock.h"
#include "utils/atomic.h"
#include "gs_thread.h"
@ -28,6 +29,22 @@ typedef volatile uint64 pg_atomic_uint64;
#endif
extern const char *const MainLWLockNames[];
const int MAX_LWLOCK_NAME_LENTH = 64;
typedef struct LWLOCK_PARTITION_DESC {
char name[MAX_LWLOCK_NAME_LENTH];
int defaultNumPartition;
int minNumPartition;
int maxNumPartition;
} LWLOCK_PARTITION_DESC;
const struct LWLOCK_PARTITION_DESC LWLockPartInfo[] = {
{"CLOG_PART", 256, 1, 256},
{"CSNLOG_PART", 512, 1, 512},
{"LOG2_LOCKTABLE_PART", 4, 4, 16}, /* lock table partition range is 2^4 to 2^16 */
{"TWOPHASE_PART", 1, 1, 64},
};
/*
* It's a bit odd to declare NUM_BUFFER_PARTITIONS and NUM_LOCK_PARTITIONS
* here, but we need them to figure out offsets within MainLWLockArray, and having
@ -54,13 +71,19 @@ extern const char *const MainLWLockNames[];
#define NUM_INSTANCE_REALTIME_PARTITIONS 32
/* CSN log partitions */
#define NUM_CSNLOG_PARTITIONS 512
#define MAX_NUM_CSNLOG_PARTITIONS (LWLockPartInfo[CSNLOG_PART].maxNumPartition)
#define NUM_CSNLOG_PARTITIONS (g_instance.attr.attr_storage.num_internal_lock_partitions[CSNLOG_PART])
/* Clog partitions */
#define NUM_CLOG_PARTITIONS 256
#define MAX_NUM_CLOG_PARTITIONS (LWLockPartInfo[CLOG_PART].maxNumPartition)
#define NUM_CLOG_PARTITIONS (g_instance.attr.attr_storage.num_internal_lock_partitions[CLOG_PART])
/* Twophase State partitions */
#define NUM_TWOPHASE_PARTITIONS (g_instance.attr.attr_storage.num_internal_lock_partitions[TWOPHASE_PART])
/* Number of partitions the shared lock tables are divided into */
#define LOG2_NUM_LOCK_PARTITIONS 4
#define LOG2_NUM_LOCK_PARTITIONS (g_instance.attr.attr_storage.num_internal_lock_partitions[LOG2_LOCKTABLE_PART])
#define NUM_LOCK_PARTITIONS (1 << LOG2_NUM_LOCK_PARTITIONS)
/* Number of partitions the shared predicate lock tables are divided into */
@ -88,50 +111,65 @@ extern const char *const MainLWLockNames[];
/* Number of partions the io state hashtable */
#define NUM_IO_STAT_PARTITIONS 128
/* Number of partitions the xid => procid hashtable */
#define NUM_PROCXACT_PARTITIONS 128
/* Number of partions the global sequence hashtable */
#define NUM_GS_PARTITIONS 1024
/* Number of partions the global workload cache hashtable */
#define NUM_GWC_PARTITIONS 64
#define NUM_STARTBLOCK_PARTITIONS 128
/* Number of partions of the segment head buffer */
#define NUM_SEGMENT_HEAD_PARTITIONS 128
#ifdef WIN32
#define NUM_INDIVIDUAL_LWLOCKS 100
#define NUM_INDIVIDUAL_LWLOCKS 113
#endif
/*
* WARNING---Please keep the order of LWLockTrunkOffset and BuiltinTrancheIds consistent!!!
*/
/* Offsets for various chunks of preallocated lwlocks in main array. */
enum LWLockTrunkOffset {
FirstBufMappingLock = NUM_INDIVIDUAL_LWLOCKS,
FirstLockMgrLock = FirstBufMappingLock + NUM_BUFFER_PARTITIONS,
FirstPredicateLockMgrLock = FirstLockMgrLock + NUM_LOCK_PARTITIONS,
FirstOperatorRealTLock = FirstPredicateLockMgrLock+ NUM_PREDICATELOCK_PARTITIONS,
FirstOperatorHistLock = FirstOperatorRealTLock + NUM_OPERATOR_REALTIME_PARTITIONS,
FirstSessionRealTLock = FirstOperatorHistLock + NUM_OPERATOR_HISTORY_PARTITIONS,
FirstSessionHistLock = FirstSessionRealTLock + NUM_SESSION_REALTIME_PARTITIONS,
FirstInstanceRealTLock = FirstSessionHistLock + NUM_SESSION_HISTORY_PARTITIONS,
/* Cache Mgr lock IDs */
FirstCacheSlotMappingLock = FirstInstanceRealTLock + NUM_INSTANCE_REALTIME_PARTITIONS,
FirstCSNBufMappingLock = FirstCacheSlotMappingLock + NUM_CACHE_BUFFER_PARTITIONS,
FirstCBufMappingLock = FirstCSNBufMappingLock + NUM_CSNLOG_PARTITIONS,
/* Instrumentaion */
FirstUniqueSQLMappingLock = FirstCBufMappingLock + NUM_CLOG_PARTITIONS,
FirstInstrUserLock = FirstUniqueSQLMappingLock + NUM_UNIQUE_SQL_PARTITIONS,
/* global plan cache */
FirstGPCMappingLock = FirstInstrUserLock + NUM_INSTR_USER_PARTITIONS,
FirstGPCPrepareMappingLock = FirstGPCMappingLock + NUM_GPC_PARTITIONS,
/* ASP */
FirstASPMappingLock = FirstGPCPrepareMappingLock + NUM_GPC_PARTITIONS,
/* global sequence */
FirstGlobalSeqLock = FirstASPMappingLock + NUM_UNIQUE_SQL_PARTITIONS,
#define FirstBufMappingLock (NUM_INDIVIDUAL_LWLOCKS)
#define FirstLockMgrLock (FirstBufMappingLock + NUM_BUFFER_PARTITIONS)
#define FirstPredicateLockMgrLock (FirstLockMgrLock + NUM_LOCK_PARTITIONS)
#define FirstOperatorRealTLock (FirstPredicateLockMgrLock + NUM_PREDICATELOCK_PARTITIONS)
#define FirstOperatorHistLock (FirstOperatorRealTLock + NUM_OPERATOR_REALTIME_PARTITIONS)
#define FirstSessionRealTLock (FirstOperatorHistLock + NUM_OPERATOR_HISTORY_PARTITIONS)
#define FirstSessionHistLock (FirstSessionRealTLock + NUM_SESSION_REALTIME_PARTITIONS)
#define FirstInstanceRealTLock (FirstSessionHistLock + NUM_SESSION_HISTORY_PARTITIONS)
/* Cache Mgr lock IDs */
#define FirstCacheSlotMappingLock (FirstInstanceRealTLock + NUM_INSTANCE_REALTIME_PARTITIONS)
#define FirstCSNBufMappingLock (FirstCacheSlotMappingLock + NUM_CACHE_BUFFER_PARTITIONS)
#define FirstCBufMappingLock (FirstCSNBufMappingLock + NUM_CSNLOG_PARTITIONS)
/* Instrumentaion */
#define FirstUniqueSQLMappingLock (FirstCBufMappingLock + NUM_CLOG_PARTITIONS)
#define FirstInstrUserLock (FirstUniqueSQLMappingLock + NUM_UNIQUE_SQL_PARTITIONS)
/* global plan cache */
#define FirstGPCMappingLock (FirstInstrUserLock + NUM_INSTR_USER_PARTITIONS)
/* ASP */
#define FirstASPMappingLock (FirstGPCMappingLock + NUM_GPC_PARTITIONS)
/* global sequence */
#define FirstGlobalSeqLock (FirstASPMappingLock + NUM_UNIQUE_SQL_PARTITIONS)
/* global workload cache */
#define FirstGWCMappingLock (FirstGlobalSeqLock + NUM_GS_PARTITIONS)
FirstNormalizedSqlLock = FirstGlobalSeqLock + NUM_GS_PARTITIONS,
FirstMPFLLock = FirstNormalizedSqlLock + NUM_NORMALIZED_SQL_PARTITIONS,
#define FirstNormalizedSqlLock (FirstGWCMappingLock + NUM_GWC_PARTITIONS)
#define FirstMPFLLock (FirstNormalizedSqlLock + NUM_NORMALIZED_SQL_PARTITIONS)
#define FirstNGroupMappingLock (FirstMPFLLock + NUM_MAX_PAGE_FLUSH_LSN_PARTITIONS)
#define FirstIOStatLock (FirstNGroupMappingLock + NUM_NGROUP_INFO_PARTITIONS)
/* undo space & trans group mapping */
#define FirstProcXactMappingLock (FirstIOStatLock + NUM_IO_STAT_PARTITIONS)
#define FirstStartBlockMappingLock (FirstProcXactMappingLock + NUM_PROCXACT_PARTITIONS)
/* segment head */
#define FirstSegmentHeadLock (FirstStartBlockMappingLock + NUM_STARTBLOCK_PARTITIONS)
#define FirstTwoPhaseStateLock (FirstSegmentHeadLock + NUM_SEGMENT_HEAD_PARTITIONS)
FirstNGroupMappingLock = FirstMPFLLock + NUM_MAX_PAGE_FLUSH_LSN_PARTITIONS,
FirstIOStatLock = FirstNGroupMappingLock + NUM_NGROUP_INFO_PARTITIONS,
/* must be last: */
NumFixedLWLocks = FirstIOStatLock + NUM_IO_STAT_PARTITIONS
};
/* must be last: */
#define NumFixedLWLocks (FirstTwoPhaseStateLock + NUM_TWOPHASE_PARTITIONS)
/*
* WARNING----Please keep BuiltinTrancheIds and BuiltinTrancheNames consistent!!!
@ -157,12 +195,17 @@ enum BuiltinTrancheIds
LWTRANCHE_UNIQUE_SQLMAPPING,
LWTRANCHE_INSTR_USER,
LWTRANCHE_GPC_MAPPING,
LWTRANCHE_GPC_PREPARE_MAPPING,
LWTRANCHE_USPACE_TRANSGRP_MAPPING,
LWTRANCHE_PROC_XACT_MAPPING,
LWTRANCHE_ASP_MAPPING,
LWTRANCHE_GlobalSeq,
LWTRANCHE_GWC_MAPPING,
LWTRANCHE_NORMALIZED_SQL,
LWTRANCHE_START_BLOCK_MAPPING,
LWTRANCHE_BUFFER_IO_IN_PROGRESS,
LWTRANCHE_BUFFER_CONTENT,
LWTRANCHE_UNDO_ZONE,
LWTRANCHE_UNDO_SPACE,
LWTRANCHE_DATA_CACHE,
LWTRANCHE_META_CACHE,
LWTRANCHE_PROC,
@ -190,6 +233,8 @@ enum BuiltinTrancheIds
LWTRANCHE_WAL_FLUSH_WAIT,
LWTRANCHE_WAL_BUFFER_INIT_WAIT,
LWTRANCHE_WAL_INIT_SEGMENT,
LWTRANCHE_SEGHEAD_PARTITION,
LWTRANCHE_TWOPHASE_STATE,
/*
* Each trancheId above should have a corresponding item in BuiltinTrancheNames;
*/
@ -318,6 +363,9 @@ extern void CreateLWLocks(void);
extern void RequestAddinLWLocks(int n);
extern const char* GetBuiltInTrancheName(int trancheId);
extern void SetLWLockPartDefaultNum(void);
extern void CheckAndSetLWLockPartInfo(const List* res);
extern void CheckLWLockPartNumRange(void);
/*
* There is another, more flexible method of obtaining lwlocks. First, call

View File

@ -183,13 +183,6 @@ struct PGPROC {
pg_time_t myStartTime;
syscalllock deleMemContextMutex;
/*
* All PROCLOCK objects for locks held or awaited by this backend are
* linked into one of these lists, according to the partition number of
* their lock.
*/
SHM_QUEUE myProcLocks[NUM_LOCK_PARTITIONS];
/* Support for group XID clearing. */
/* true, if member of ProcArray group waiting for XID clear */
bool procArrayGroupMember;
@ -264,6 +257,13 @@ struct PGPROC {
char *dw_unaligned_buf;
char *dw_buf;
volatile int32 dw_pos;
/*
* All PROCLOCK objects for locks held or awaited by this backend are
* linked into one of these lists, according to the partition number of
* their lock.
*/
SHM_QUEUE myProcLocks[1];
};
/* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock/lock.h. */

View File

@ -30,6 +30,8 @@
#include "securec.h"
#include "securec_check.h"
#include <algorithm>
/* stands for non-int type */
struct __type_true {};

View File

@ -316,6 +316,7 @@ extern bool check_asp_flush_mode(char** newval, void** extra, GucSource source);
/* in access/transam/xlog.c */
extern bool check_wal_buffers(int* newval, void** extra, GucSource source);
extern bool check_wal_insert_status_entries(int* newval, void** extra, GucSource source);
extern void assign_xlog_sync_method(int new_sync_method, void* extra);
/* in tcop/stmt_retry.cpp */
@ -432,5 +433,6 @@ extern void set_qunit_case_number_hook(int newval, void* extra);
#endif
extern GucContext get_guc_context();
extern void InitializeNumLwLockPartitions(void);
#endif /* GUC_H */