-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Makefile changes to build CDC in builddir for pgoutput and wal2json. (#…
…6827) DESCRIPTION: Makefile changes to build different versions of CDC decoder for different base decoders like pgoutput and wal2json with the same name and copy it to $packagelib/cdc_decoders dir. This helps the user to use logical replication slots normally with pgoutput without being aware of CDC decoder. 1) Changed src/backend/distributed/cdc/Makefile to setup a build directory for CDC in build-cdc-$(DECODER) dir and copy the source files (.c.h and Makefile.decoder) to the build dir and build it for each base decoder. 2) copy the pgoutput.so and wal2json.so into the above build dir and install them in PG packagelibdir/citus_decoders directory. 3)Added a testcase 016_cdc_wal2json.pl for testing the wal2json decoder using pg_recv_logical_changes function.
- Loading branch information
1 parent
ded728b
commit 2877fec
Showing
5 changed files
with
117 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,45 @@ | ||
ifndef DECODER | ||
DECODER = pgoutput | ||
endif | ||
citus_top_builddir = ../../../.. | ||
include $(citus_top_builddir)/Makefile.global | ||
|
||
MODULE_big = citus_$(DECODER) | ||
citus_subdir = src/backend/distributed/cdc | ||
citus_top_builddir = ../../../.. | ||
citus_decoders_dir = $(DESTDIR)$(pkglibdir)/citus_decoders | ||
SRC_DIR = $(citus_abs_top_srcdir)/$(citus_subdir) | ||
|
||
OBJS += cdc_decoder.o cdc_decoder_utils.o | ||
#List of supported based decoders. Add new decoders here. | ||
cdc_base_decoders :=pgoutput wal2json | ||
|
||
include $(citus_top_builddir)/Makefile.global | ||
all: build-cdc-decoders | ||
|
||
copy-decoder-files-to-build-dir: | ||
$(eval DECODER_BUILD_DIR=build-cdc-$(DECODER)) | ||
mkdir -p $(DECODER_BUILD_DIR) | ||
@for file in $(SRC_DIR)/*.c $(SRC_DIR)/*.h; do \ | ||
if [ -f $$file ]; then \ | ||
if [ -f $(DECODER_BUILD_DIR)/$$(basename $$file) ]; then \ | ||
if ! diff -q $$file $(DECODER_BUILD_DIR)/$$(basename $$file); then \ | ||
cp $$file $(DECODER_BUILD_DIR)/$$(basename $$file); \ | ||
fi \ | ||
else \ | ||
cp $$file $(DECODER_BUILD_DIR)/$$(basename $$file); \ | ||
fi \ | ||
fi \ | ||
done | ||
cp $(SRC_DIR)/Makefile.decoder $(DECODER_BUILD_DIR)/Makefile | ||
|
||
build-cdc-decoders: | ||
$(foreach base_decoder,$(cdc_base_decoders),$(MAKE) DECODER=$(base_decoder) build-cdc-decoder;) | ||
|
||
install-cdc-decoders: | ||
$(foreach base_decoder,$(cdc_base_decoders),$(MAKE) DECODER=$(base_decoder) -C build-cdc-$(base_decoder) install;) | ||
|
||
clean-cdc-decoders: | ||
$(foreach base_decoder,$(cdc_base_decoders),rm -rf build-cdc-$(base_decoder);) | ||
|
||
override CFLAGS += -DDECODER=\"$(DECODER)\" -I$(citus_abs_top_srcdir)/include | ||
override CPPFLAGS += -DDECODER=\"$(DECODER)\" -I$(citus_abs_top_srcdir)/include | ||
|
||
install: install-cdc | ||
build-cdc-decoder: | ||
$(MAKE) DECODER=$(DECODER) copy-decoder-files-to-build-dir | ||
$(MAKE) DECODER=$(DECODER) -C build-cdc-$(DECODER) | ||
|
||
clean: clean-cdc | ||
install: install-cdc-decoders | ||
|
||
install-cdc: | ||
mkdir -p '$(citus_decoders_dir)' | ||
$(INSTALL_SHLIB) citus_$(DECODER).so '$(citus_decoders_dir)/$(DECODER).so' | ||
clean: clean-cdc-decoders | ||
|
||
clean-cdc: | ||
rm -f '$(DESTDIR)$(datadir)/$(datamoduledir)/citus_decoders/$(DECODER).so' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
MODULE_big = citus_$(DECODER) | ||
|
||
citus_decoders_dir = $(DESTDIR)$(pkglibdir)/citus_decoders | ||
|
||
citus_top_builddir = ../../../../.. | ||
citus_subdir = src/backend/distributed/cdc/cdc_$(DECODER) | ||
|
||
OBJS += cdc_decoder.o cdc_decoder_utils.o | ||
|
||
include $(citus_top_builddir)/Makefile.global | ||
|
||
override CFLAGS += -DDECODER=\"$(DECODER)\" -I$(citus_abs_top_srcdir)/include | ||
override CPPFLAGS += -DDECODER=\"$(DECODER)\" -I$(citus_abs_top_srcdir)/include | ||
|
||
install: install-cdc | ||
|
||
clean: clean-cdc | ||
|
||
install-cdc: | ||
mkdir -p '$(citus_decoders_dir)' | ||
$(INSTALL_SHLIB) citus_$(DECODER).so '$(citus_decoders_dir)/$(DECODER).so' | ||
|
||
clean-cdc: | ||
rm -f '$(DESTDIR)$(datadir)/$(datamoduledir)/citus_decoders/$(DECODER).so' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Schema change CDC test for Citus | ||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
|
||
use lib './t'; | ||
use cdctestlib; | ||
|
||
use threads; | ||
|
||
# Initialize co-ordinator node | ||
my $select_stmt = qq(SELECT * FROM data_100008 ORDER BY id;); | ||
my $result = 0; | ||
|
||
### Create the citus cluster with coordinator and two worker nodes | ||
our ($node_coordinator, @workers) = create_citus_cluster(1,"localhost",57636); | ||
|
||
print("coordinator port: " . $node_coordinator->port() . "\n"); | ||
print("worker0 port:" . $workers[0]->port() . "\n"); | ||
|
||
my $initial_schema = " | ||
CREATE TABLE data_100008( | ||
id integer, | ||
data text, | ||
PRIMARY KEY (data));"; | ||
|
||
$node_coordinator->safe_psql('postgres',$initial_schema); | ||
$node_coordinator->safe_psql('postgres','ALTER TABLE data_100008 REPLICA IDENTITY FULL;'); | ||
$node_coordinator->safe_psql('postgres',"SELECT pg_catalog.pg_create_logical_replication_slot('cdc_replication_slot','wal2json');"); | ||
|
||
#insert data into the data_100008 table in the coordinator node before distributing the table. | ||
$node_coordinator->safe_psql('postgres'," | ||
INSERT INTO data_100008 | ||
SELECT i, 'my test data ' || i | ||
FROM generate_series(-1,1)i;"); | ||
|
||
my $output = $node_coordinator->safe_psql('postgres',"SELECT * FROM pg_logical_slot_get_changes('cdc_replication_slot', NULL, NULL);"); | ||
print($output); | ||
|
||
my $change_string_expected = '[0,"my test data 0"]'; | ||
if ($output =~ /$change_string_expected/) { | ||
$result = 1; | ||
} else { | ||
$result = 0; | ||
} | ||
|
||
is($result, 1, 'CDC create_distributed_table - wal2json test'); | ||
$node_coordinator->safe_psql('postgres',"SELECT pg_drop_replication_slot('cdc_replication_slot');"); | ||
|
||
done_testing(); |