Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
27e4fa7
Support separation of catalog and compute.
Aug 10, 2023
5c872ed
1. add global variable enable_serverless, default to false, set to tr…
Aug 11, 2023
7e7c992
disable WAL-log information required only for Hot Standby in serverless
Aug 16, 2023
1c71dfd
Add support for creating cluster with single master, and only query o…
HuSen8891 Aug 20, 2023
7451a8a
Add: Support to create hashdata table with randomly distribution.
HuSen8891 Aug 23, 2023
84f4898
1. set distributedXid to LocalTransactionId 2. do not send FTS Probe …
HuSen8891 Aug 29, 2023
5f26818
Feature: support subtransaction and savepoint
HuSen8891 Aug 31, 2023
9539d27
Fix: Only master can set transaction status
HuSen8891 Sep 1, 2023
3559b79
Add extensible smgr slot for other storage format.
zhangwenchao-123 Aug 30, 2023
bc464ec
Feature: add dml hook
gongxun0928 Sep 11, 2023
89daa53
Add main_manifest catalog table
Sep 14, 2023
4f16fc0
Add hooks for plugins to get control in transientrel_init/intorel_ini…
HuSen8891 Sep 18, 2023
8e56e4f
Implement extensible libpq protocol.
zhangwenchao-123 Sep 4, 2023
a0c6b4f
Add vacuum full in serverless (#209)
roseduan Sep 20, 2023
41659a1
change storage_am related catalog table main_manifest field type from…
wangliang03 Sep 21, 2023
8f4a8df
Add regress pipeline for branch union_store_catalog and fix compile e…
zhangwenchao-123 Sep 21, 2023
295eb56
bugfix: support hashdata tableam in Orca (#222)
gongxun0928 Sep 26, 2023
d4e979f
support analyze for unionstore table in cloudberry (#207)
gongxun0928 Sep 26, 2023
1a22c6d
New altertable rewrite dispatch policy (#223)
wangliang03 Sep 28, 2023
76aa413
Fix: do not commit subtransaction through DTX protocol. (#226)
HuSen8891 Oct 8, 2023
ca08709
Add: new hooks for plugins to get control in syscache.
HuSen8891 Oct 10, 2023
68a1212
Change myTempNamespace from static variable to extern variable.
zhangwenchao-123 Oct 9, 2023
3137ea5
Implement drop warehouse
zhangwenchao-123 Oct 10, 2023
08b65a7
Add: new hook for plugins to validate the relation
HuSen8891 Oct 13, 2023
6414895
fix triggers
gongxun0928 Sep 26, 2023
6b42b22
Add: some interfaces to get transaction state and xids
Oct 23, 2023
f81b4d9
Fix copy from freeze will check subtransaction id in QEs.
zhangwenchao-123 Nov 1, 2023
bea9c79
Add: new hook to get control in getgpsegmentCount. (#277)
HuSen8891 Nov 3, 2023
f660c74
make main_manifest table not shared (#311)
roseduan Nov 21, 2023
7b54d03
Fix: enable trigger throught FDW in the serverless architecture.
lss602726449 Nov 21, 2023
d19b5c4
Add interface and export struct to public. (#304)
HuSen8891 Nov 23, 2023
e187e30
Judge whether commands need to be dispatched to QEs in QD (#314)
zhangwenchao-123 Nov 24, 2023
fb499c3
Support cloud manager (#296)
roseduan Nov 27, 2023
a6c1161
Add cache invaladation synchronization amoung QD and QEs.
zhangwenchao-123 Oct 19, 2023
f7d5a17
Fix some errors in cherry pick
oppenheimer01 Apr 16, 2025
18dd3ad
Fix copy from where clause of randomly distribution table.
zhangwenchao-123 Dec 26, 2023
3d6d7ce
Fix: dispatch Alter Domain statement to QE.
Dec 13, 2023
bfbc114
Fix before delete/update row trgger assert in serverless architecture
lss602726449 Dec 13, 2023
9358142
Enhancement: support dispatch metadata to QE from QD.
Dec 13, 2023
c74c045
Add configure option --enable-gophermeta, --enable-datalake
lss602726449 Dec 8, 2023
d96e3a7
Support vbf and compress.
Dec 27, 2023
11cc8c4
Fix dispatch set command will error out when there is no warehouse.
zhangwenchao-123 Dec 13, 2023
c0b9687
Feature: Support Fault Tolerant Service (FTS)
Mar 5, 2024
c365a23
Feature: support scale warehouse horizontally
Dec 18, 2023
6105a59
Supports database level encryption, with each database using a key.
Dec 8, 2023
d2ddf28
When read tuple, need to get all the data. When write tuple, only wri…
Dec 21, 2023
c712ac2
Enhancement: optimize the filepath and keep snapshot of table.
Jan 9, 2024
af709ea
Fix: refresh shared buffers and disable hint bits.
Jan 18, 2024
9d2965d
Add new hashdata am oid to RelationIsNonblockRelation
oppenheimer01 Jan 19, 2024
9a6138a
Fix: collect stat from QE to QD
lss602726449 Jan 21, 2024
4b9df10
Fix: storage the keys in the dfs tablespace
May 13, 2024
b3a2278
Enable delete after trigger
oppenheimer01 Jan 24, 2024
ba27c51
Fix: parallel regression test failures
Jan 25, 2024
2fc2068
storage_am: fix hashdata table size
Jan 29, 2024
5d35c3e
Add ci for remote storage
Feb 22, 2024
3d911f9
Fix error for cherry pick
oppenheimer01 Apr 18, 2025
8c4a8b0
Fix: change the dispatch manifest hook point
lss602726449 Feb 1, 2024
185c128
pg_ctl: check dtm process to judge is_coordinator.
Feb 2, 2024
b17890f
Fix: zlib and gangsize test cases, clean up dispatcherState in time
Feb 2, 2024
3ee830c
gpconfig: add --warehouse option, default is test.
yjhjstz Feb 2, 2024
e0ab711
Fix CTAS crash.
avamingli Feb 4, 2024
87786ad
Fix gitignore.
avamingli Feb 4, 2024
fc61c38
Fix: gpdiffcheck/query_finish_pending/segspace/dispatch cases
Feb 21, 2024
bd6581c
fix hang when shutdown in checkpoint
yjhjstz Feb 5, 2024
64df9e8
fix memory overflow in Dispatch Context.
yjhjstz Feb 6, 2024
ac14da0
Extend a new AM method to do acquire sample rows.
zhangwenchao-123 Jan 29, 2024
e063308
Analyze table change to happen on QD.
Feb 28, 2024
9dc4118
Fix: only update distribution policy for 'SET DISTRIBUTED BY' statement
Feb 28, 2024
0ab8386
Fix: use CBDB bin/include to build unionstore
lss602726449 Feb 28, 2024
f081ddd
Fix hashdata storage `vacuum full`
Feb 29, 2024
08acdfd
Fix: set numsegments of distribution policy to zero for partition chi…
Mar 1, 2024
c639368
Retire `enable_serverless` (Part 1)
Mar 6, 2024
c72e196
fix minirepro
Mar 8, 2024
89f42f2
Fix use_physical_tlist to consider hashdata column store.
Mar 5, 2024
1225711
Support `createdb`, `dropdb`, etc. tools
Mar 5, 2024
f59f296
Fix plan diffs, including:
Mar 7, 2024
b687458
Optimize simple delete not project whole row
Mar 5, 2024
3d2bf9c
Fix tablespace bug
Mar 5, 2024
a1423ac
Feature: support user defined heap table
Mar 13, 2024
f82cf47
Fix fts probe issue after pg_ctl restart
Mar 13, 2024
54c69a5
Fix gpsd
Mar 12, 2024
32ef8c1
Support partition on heap table
Mar 20, 2024
db2596b
Add an auto switch warehouse for chaos test
Mar 19, 2024
872cdd4
Add serial schedule CI for heap table
Mar 27, 2024
c31e19f
Feature: support warehouse access control management
Apr 7, 2024
e6ede18
Collect catalog and dispatch to qes
oppenheimer01 May 31, 2024
1b01f4d
Add pg_calss.relreuseattrs to identify partition could reuse parent's…
avamingli Apr 17, 2024
6cec784
Add autopartition grammar in parser
Apr 16, 2024
0160f25
Support IF [NOT] EXISTS when CREATE/DROP WAREHOUSE.
avamingli Apr 16, 2024
494f03b
Feature: support min/max filter in storage_am.
Apr 23, 2024
9d03511
support storage type check for column add
wangliang03 Apr 19, 2024
0c93bb5
change the SCAN_SUPPORT_DEFAULT_COLUMNs macro value
wangliang03 Apr 22, 2024
619c238
Fix: use XLogRecGetBlockTag to get block number in brin_redo.
Apr 25, 2024
e1ef352
Refactory hashdata_manifest(json format)
May 7, 2024
7c47ea7
Feature: create role DEFAULTWAREHOUSE and guc
May 16, 2024
2c84254
Fix gp_tablespace_location
May 24, 2024
bda6e5c
Fix policy relcache changed issue.
avamingli May 16, 2024
678deb1
New tool hd_ctl to create/drop distributed warehouse
May 15, 2024
8121358
Support Insert for AutoPartition table
May 27, 2024
d5c74b1
concurrent_insert
lss602726449 May 27, 2024
46dd81e
Table files cleanup after Drop/Truncate/Vacuum
Jun 7, 2024
6622671
Feature: optimize simple aggregate query
May 30, 2024
45ee0c7
create warehouse OPTIONS
avamingli May 16, 2024
5fbf571
Feature: recongnize AM by tablespace
Jul 1, 2024
9c13378
Move all ProcessUtility into hashdata_utility
May 31, 2024
07bc62a
Feature: AutoPartition support Copy...FROM... command
Jun 7, 2024
4d60ff7
Make a start dispatch for the catalog used in init backend
oppenheimer01 Jun 7, 2024
671d633
Miscellaneous fix: utility mode, hd_ctl enhancement, scripting
Jun 17, 2024
78cff11
Support vectorization on hashdata table
Jun 5, 2024
916d709
Incremental Agg Plan based on materialized views.
avamingli Jun 17, 2024
382fd6c
Fix the record empty error in init plpgsql
oppenheimer01 Jun 7, 2024
56b8746
Fix a mistake on RelationReloadNailed
oppenheimer01 Jun 11, 2024
659edd0
Do not use AccessExclusiveLock in Manifest
oppenheimer01 Jun 9, 2024
b8f37ef
Remove some node dispatch code
oppenheimer01 Jun 4, 2024
d2fd223
Feature: support group aggregation defer ivm maintenance.
Jun 28, 2024
956fd46
Fix some compile error
oppenheimer01 Apr 23, 2025
8845bde
Fix: use IS_QUERY_DISPATCHER() to distinguish backends while accessin…
Jun 17, 2024
ff6717e
Serverless QE never hold relation lock
Jun 18, 2024
9ea9920
Revert "Add cache invaladation synchronization amoung QD and QEs."
lss602726449 Jun 13, 2024
96fc191
Fix: fix serveral problem in catalog dispatch
lss602726449 Jun 13, 2024
0841ca6
Fix flake test for copy pg_internal.init
oppenheimer01 Jun 18, 2024
10d36b8
Enable catalog collection on all the workers on master
oppenheimer01 Jul 1, 2024
4b091a6
Add a new table am routine ScanCatalogPrepare
oppenheimer01 Jun 27, 2024
f6a03fe
Enable autovacuum process
Jun 21, 2024
4c98882
Remove useless function UpdateManifestRecord.
avamingli Jun 25, 2024
c24cbbb
Support Subquery in Append Agg.
avamingli Jul 8, 2024
ed1fdc4
Fix: use MACRO SERVERLESS instead of GUC enable_serverless
Jun 28, 2024
4d1fc06
Enhance: Support for alter warehouse name suspend/resume/options
lss602726449 Jul 25, 2024
068ea37
Refactor: use MACRO SERVERLESS to improve readability and maintainabi…
Jul 19, 2024
5cd6a0b
Add SERVERLESS macro on the function load/write rel cache function
oppenheimer01 Jul 2, 2024
56d1c77
Enhancement: adjust tablespace for support serverless architecture
Jul 25, 2024
f3c161b
Refactor: add MACRO SERVERLESS to catalog dispatching related code
Jul 3, 2024
79a256e
Fix: auto analyze inherited table error
Jul 22, 2024
96fa89f
Use aqumv public function in grouping paths.
avamingli Jul 22, 2024
570dae9
Remove regular lock on segment
oppenheimer01 Jul 12, 2024
cd075ee
Fix work around of materialized view data status.
avamingli Jul 19, 2024
2327c30
Fix: fts coredump
Jul 18, 2024
5f31cab
Support min, max in Append Agg Plan.
avamingli Jul 19, 2024
d865aa0
Add create_plan_hook and cursor option
Jul 25, 2024
ab95372
[CLOUD] Enable delta scan vectorization
Jul 25, 2024
6c33730
Fix: Retry get hostip from DNS if failed
lss602726449 Jul 25, 2024
f6fd386
Fix symbol not found in backstrace
Aug 22, 2024
64ccba0
[CLOUD] Remove unionstore extention from segment
oppenheimer01 Sep 19, 2024
bef94eb
disable autovacuum temporarily
Aug 5, 2024
eaeb741
Add MACRO 'FAULT_INJECTOR'/'SERVERLESS' to related code
Aug 5, 2024
3afd6ce
Support COUNT with const value in Append AGG plan.
avamingli Aug 6, 2024
45d60ba
Force CTAS distribution to random in serverless mode.
avamingli Aug 6, 2024
88c92ac
Forbid connecting to QE in utility mode
Aug 19, 2024
ecbb91a
Make column case-sensitivity only for output column.
zhangwenchao-123 Aug 8, 2024
779bb8c
Clean pg_cron guc optimizer,enable_answer_query_using_materialized_vi…
Aug 12, 2024
cdc2ae2
Eliminate const expressions for Append AGG.
avamingli Aug 10, 2024
2226561
Build db without cloud extension
Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@ lib*.pc
/compile_commands.json
/tmp_install/
/.cache/
/install/
/install/
dependencies.sh
compile_commands.json
32 changes: 32 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ enable_mapreduce
enable_catalog_ext
enable_serverless
enable_orca
enable_serverless
autodepend
PKG_CONFIG_LIBDIR
PKG_CONFIG_PATH
Expand Down Expand Up @@ -8378,6 +8379,37 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: checking whether to build with catalog extension... $enable_catalog_ext" >&5
$as_echo "checking whether to build with catalog extension... $enable_catalog_ext" >&6; }

#
# Enable serverless architecture
#


# Check whether --enable-serverless was given.
if test "${enable_serverless+set}" = set; then :
enableval=$enable_serverless;
case $enableval in
yes)

$as_echo "#define SERVERLESS 1" >>confdefs.h

;;
no)
:
;;
*)
as_fn_error $? "no argument expected for --enable-serverless option" "$LINENO" 5
;;
esac

else
enable_serverless=no

fi


{ $as_echo "$as_me:${as_lineno-$LINENO}: result: checking whether to use serverless architecture of Cloudberry ... $enable_serverless" >&5
$as_echo "checking whether to use serverless architecture of Cloudberry ... $enable_serverless" >&6; }


#
# Enable serverless mode
Expand Down
29 changes: 29 additions & 0 deletions contrib/hashdata_chaos/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# contrib/hashdata_chaos/Makefile
subdir = contrib/hashdata_chaos
top_builddir = ../..

MODULE_big = hashdata_chaos
PGFILEDESC = "hashdata chaos framework"

OBJS = hashdata_chaos.o \
reghouse.o

EXTENSION = hashdata_chaos
DATA = hashdata_chaos--1.0.sql

# REGRESS =

# EXTRA_CLEAN =

# REGRESS_OPTS =

ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir = contrib/hashodata_chaos
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
46 changes: 46 additions & 0 deletions contrib/hashdata_chaos/hashdata_chaos--1.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* contrib/hashdata_chaos/hashdata_chaos--1.0.sql */

-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION hashdata_chaos" to load this file. \quit

CREATE FUNCTION hashdata_chaos_warehouse_begin(float8)
RETURNS BOOLEAN
AS 'MODULE_PATHNAME'
LANGUAGE C VOLATILE EXECUTE ON COORDINATOR;

CREATE FUNCTION hashdata_chaos_warehouse_end()
RETURNS BOOLEAN
AS 'MODULE_PATHNAME'
LANGUAGE C VOLATILE EXECUTE ON COORDINATOR;

CREATE TYPE reghouse;

CREATE FUNCTION reghousein(cstring)
RETURNS reghouse
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;

CREATE FUNCTION reghouseout(reghouse)
RETURNS cstring
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;

CREATE FUNCTION reghouserecv(internal)
RETURNS reghouse
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;

CREATE FUNCTION reghousesend(reghouse)
RETURNS bytea
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT;

CREATE TYPE reghouse(
INPUT = reghousein,
OUTPUT = reghouseout,
RECEIVE = reghouserecv,
SEND = reghousesend,
ALIGNMENT = int4,
INTERNALLENGTH = 4,
PASSEDBYVALUE
)
248 changes: 248 additions & 0 deletions contrib/hashdata_chaos/hashdata_chaos.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
#include "postgres.h"

#include "funcapi.h"
#include "pg_config.h"

#include "access/genam.h"
#include "access/table.h"
#include "access/xact.h"
#include "catalog/gp_warehouse.h"
#include "cdb/cdbvars.h"
#include "storage/ipc.h"
#include "storage/lwlock.h"
#include "storage/shmem.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"

PG_MODULE_MAGIC;

#define MAX_WAREHOUSE_SIZE (8)
#define CHAOS_LOCK_NAME "hashdata_chaos_lock"
#define CHAOS_OBJ_NAME "HashdataChaosShmem"

/* TODO: we need a local cache and pin some warehouse if chaos test start */
typedef struct HashdataChaosShmem_s {
float8 threshold;
int8 numWarehouses;
Oid oidWarehouses[MAX_WAREHOUSE_SIZE];
} HashdataChaosShmem_s;

/* function declarations */
void _PG_init(void);
void _PG_fini(void);

extern Datum hashdata_chaos_warehouse_begin(PG_FUNCTION_ARGS);
extern Datum hashdata_chaos_warehouse_end(PG_FUNCTION_ARGS);

static void hashdata_chaos_shmem_startup(void);
static shmem_startup_hook_type prev_shmem_startup_hook = NULL;
static void hashdata_chaos_simple_query_hook(void (*exec_simple_query)(const char *), void *whereToSendOutput);

/* Links to shared memory state */
static HashdataChaosShmem_s *chaosShmem = NULL;
static LWLock *chaosLock = NULL;

/*
* Module load callback
*/
void
_PG_init(void)
{
#ifdef FAULT_INJECTOR
if (!process_shared_preload_libraries_in_progress)
return;

RequestNamedLWLockTranche(CHAOS_LOCK_NAME, 1);
RequestAddinShmemSpace(sizeof(HashdataChaosShmem_s));

prev_shmem_startup_hook = shmem_startup_hook;
shmem_startup_hook = hashdata_chaos_shmem_startup;

execSimpleQuery_Hook = hashdata_chaos_simple_query_hook;
#endif /* FAULT_INJECTOR*/
}

/*
* shmem_startup hook: allocate or attach to shared memory,
* then load any pre-existing statistics from file.
* Also create and load the query-texts file, which is expected to exist
* (even if empty) while the module is enabled.
*/
static void
hashdata_chaos_shmem_startup(void)
{
bool found;

if (prev_shmem_startup_hook)
{
prev_shmem_startup_hook();
}

LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);

chaosLock = &(GetNamedLWLockTranche(CHAOS_LOCK_NAME))->lock;

chaosShmem = ShmemInitStruct(CHAOS_OBJ_NAME,
sizeof(HashdataChaosShmem_s),
&found);

/* First time through */
if (!found)
MemSet(chaosShmem, 0, sizeof(HashdataChaosShmem_s));

LWLockRelease(AddinShmemInitLock);
}

PG_FUNCTION_INFO_V1(hashdata_chaos_warehouse_begin);
Datum
hashdata_chaos_warehouse_begin(PG_FUNCTION_ARGS)
{
#ifdef FAULT_INJECTOR
bool ret = false;
float8 threshold = PG_GETARG_FLOAT8(0);
text *pattern = cstring_to_text("chaos_%");

if (threshold > 1 || threshold < 0)
PG_RETURN_BOOL(ret);

LWLockAcquire(chaosLock, LW_EXCLUSIVE);
if (chaosShmem->numWarehouses == 0 &&
chaosShmem->threshold == 0.0)
{
Relation rel;
SysScanDesc scan;
HeapTuple tuple;

rel = table_open(GpWarehouseRelationId, AccessShareLock);
scan = systable_beginscan(rel, InvalidOid, false, NULL, 0, NULL);

while ((tuple = systable_getnext(scan)) != NULL)
{
if (HeapTupleIsValid(tuple))
{
text *warehouse_name = &((Form_gp_warehouse)GETSTRUCT(tuple))->warehouse_name;
Oid warehouseOid = ((Form_gp_warehouse)GETSTRUCT(tuple))->oid;

if (OidFunctionCall2(F_LIKE_TEXT_TEXT,
PointerGetDatum(warehouse_name),
PointerGetDatum(pattern)))
{
chaosShmem->oidWarehouses[chaosShmem->numWarehouses++] = warehouseOid;
}
}

if (chaosShmem->numWarehouses >= MAX_WAREHOUSE_SIZE)
break;
}

chaosShmem->threshold = threshold;
systable_endscan(scan);
table_close(rel, NoLock);
ret = (chaosShmem->numWarehouses != 0);
}
LWLockRelease(chaosLock);

PG_RETURN_BOOL(ret);
#else
ereport(WARNING,
(errcode(ERRCODE_CHAOS_FRAMEWORK),
errmsg("chaos framework disable, enable with flags --enable-faultinjector ")));

PG_RETURN_BOOL(false);
#endif
}

PG_FUNCTION_INFO_V1(hashdata_chaos_warehouse_end);
Datum hashdata_chaos_warehouse_end(PG_FUNCTION_ARGS)
{
#ifdef FAULT_INJECTOR
LWLockAcquire(chaosLock, LW_EXCLUSIVE);
MemSet(chaosShmem, 0, sizeof(HashdataChaosShmem_s));
LWLockRelease(chaosLock);

PG_RETURN_BOOL(true);
#else
ereport(WARNING,
(errcode(ERRCODE_CHAOS_FRAMEWORK),
errmsg("chaos framework disable, enable with flags --enable-faultinjector ")));

PG_RETURN_BOOL(false);
#endif
}

static bool
generate_cmd(Oid id, char *buffer, int lengh)
{
bool success = false;
HeapTuple tuple;
Relation rel;
ScanKeyData key[1];
SysScanDesc scan;

ScanKeyInit(&key[0],
Anum_gp_warehouse_oid,
BTEqualStrategyNumber, F_OIDEQ,
id);
rel = table_open(GpWarehouseRelationId, AccessShareLock);
scan = systable_beginscan(rel, GpWarehouseOidIndexId, true, NULL, 1, key);
tuple = systable_getnext(scan);
if (HeapTupleIsValid(tuple))
{
text *warehouse_name = &((Form_gp_warehouse) GETSTRUCT(tuple))->warehouse_name;
snprintf(buffer, lengh,"set warehouse to %s;", text_to_cstring(warehouse_name));
success = true;
}
systable_endscan(scan);
table_close(rel, NoLock);

return success;
}

static void
hashdata_chaos_simple_query_hook(void (*exec_simple_query)(const char *),
void *whereToSendOutput)
{
static char cmd[MAXPATHLEN];
bool doswitch = false;

if (Gp_role != GP_ROLE_DISPATCH)
{
return;
}

start_xact_command();
memset(cmd, 0, MAXPATHLEN);

if (!IsTransactionState())
{
return;
}

LWLockAcquire(chaosLock, LW_SHARED);
if (chaosShmem->numWarehouses > 0 && chaosShmem->threshold > 0)
{
float8 lottery = DatumGetFloat8(OidFunctionCall0(F_RANDOM));
doswitch = DatumGetBool(OidFunctionCall2(F_FLOAT8LT,
Float8GetDatum(lottery),
Float8GetDatum(chaosShmem->threshold)));
if (doswitch)
{
int warehouseid = random() % chaosShmem->numWarehouses;
doswitch = generate_cmd(chaosShmem->oidWarehouses[warehouseid],
cmd, MAXPATHLEN);
ereport(LOG,
(errcode(ERRCODE_CHAOS_FRAMEWORK),
errmsg("auto switch warehouse: %s", cmd)));
}
}
LWLockRelease(chaosLock);

if (doswitch)
{
CommandDest orig_whereToSendOutput = *(CommandDest *)whereToSendOutput;
*(CommandDest *)whereToSendOutput = DestNone;
exec_simple_query(cmd);
*(CommandDest *)whereToSendOutput = orig_whereToSendOutput;
}
}
5 changes: 5 additions & 0 deletions contrib/hashdata_chaos/hashdata_chaos.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# hashdata_chaos extension
comment = 'chaos switch warehouse'
default_version = '1.0'
module_pathname = '$libdir/hashdata_chaos'
relocatable = true
Loading
Loading