-
-
Notifications
You must be signed in to change notification settings - Fork 1
PostgreSQL Logical Replication Load-Balancing Example #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
clauspruefer
wants to merge
35
commits into
main
Choose a base branch
from
example-logical-replication
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
ddff950
Client config (sdmi centric)
clauspruefer dcc4b34
Single DB-node docker file
clauspruefer 337a478
Add run container shell script
clauspruefer d9b0ce0
Disable iptables in docker daemon config
clauspruefer 8503e66
Remove unrelevant runtime sub-data
clauspruefer 5692699
Add local orchestrator code
clauspruefer 054b108
Add docker metadata
clauspruefer 70a08d6
Update docker related
clauspruefer 1f0da9c
Add service metadata templates
clauspruefer bc2cacd
Add main orchestrator
clauspruefer 34c7f62
Update config
clauspruefer 75b90c4
Add json-rpc server component
clauspruefer 3676b5f
Add server start script
clauspruefer 6af53de
Add ESB metadata / processing logic
clauspruefer d5d8c05
Replace jsocket with local cleaned-up (working) version
clauspruefer ee47dcd
Fix bugs
clauspruefer 74a442e
Add missing default values
clauspruefer acdcb34
Update (bug fix, working with modified jsocket)
clauspruefer 81999a1
Add missing default values
clauspruefer f3c316a
Disable iptables globally in docker-daemon
clauspruefer adbe82e
Update RPC model
clauspruefer 2091db7
Add domain properties
clauspruefer 938d19a
Update service call metadata
clauspruefer c2ff770
Update
clauspruefer cefb386
Add global sql queries
clauspruefer 9bd2bbe
Fix path
clauspruefer 0af58da
Remove unneeded modules
clauspruefer f97c08d
Add queries
clauspruefer 87b7d7c
Increase max nodes
clauspruefer 70f8121
Make use of max_nodes config property
clauspruefer 0840382
Describe replication order
clauspruefer f8bf320
Remove empty lines
clauspruefer 1090568
Correct psycopg2 syntax
clauspruefer f1a2573
Add network reference property
clauspruefer 7ade606
Column replacement will be handled internally
clauspruefer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,13 @@ | ||
| # Precise Replication Order | ||
|
|
||
| | NodeID | SrcNode | Function | ProcOn | Command | | ||
| | ------- | ------- | ----------------- | ------ | ----------------------------- | | ||
| | Node1 | node1 | node_pub_self | node | create pub 'pub-node1-table1' | | ||
| | Node2 | node2 | node_pub_self | node | create pub 'pub-node2-table1' | | ||
| | | node2 | node_sub_2others | node | create sub 'sub-node1-table1' | | ||
| | | node1 | others_sub_2node | orch | create sub 'sub-node2-table1' | | ||
| | Node3 | node3 | node_pub_self | node | create pub 'pub-node3-table1' | | ||
| | | node3 | node_sub_2others | node | create sub 'sub-node2-table1' | | ||
| | | node3 | node_sub_2others | node | create sub 'sub-node1-table1' | | ||
| | | node2 | others_sub_2node | orch | create sub 'sub-node3-table1' | | ||
| | | node1 | others_sub_2node | orch | create sub 'sub-node3-table1' | |
11 changes: 11 additions & 0 deletions
11
example/01-logical-replication/db-node-rpc/class_mapping.py
This file contains hidden or 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,11 @@ | ||
| class_mapping = { | ||
| 'System': 'System', | ||
| 'Network': 'Network', | ||
| 'NetworkTopology': 'NetworkTopology', | ||
| 'NetIPv4': 'NetIPv4', | ||
| 'NetIPv6': 'NetIPv6', | ||
| 'TopologyHost': 'TopologyHost', | ||
| 'Database': 'Database', | ||
| 'Table': 'Table', | ||
| 'Column': 'Column' | ||
| } |
46 changes: 46 additions & 0 deletions
46
example/01-logical-replication/db-node-rpc/class_reference.py
This file contains hidden or 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,46 @@ | ||
| references = { | ||
| 'UpdateNetworkTopology': { | ||
| 'System': { | ||
| 'property_ref': 'System', | ||
| 'children': { | ||
| 'Network': { | ||
| 'property_ref': 'Network' | ||
| }, | ||
| 'NetworkTopology': { | ||
| 'property_ref': 'NetworkTopology', | ||
| 'children': { | ||
| 'NetIPv4': { | ||
| 'property_ref': 'NetIPv4' | ||
| }, | ||
| 'NetIPv6': { | ||
| 'property_ref': 'NetIPv6' | ||
| }, | ||
| 'TopologyHost': { | ||
| 'property_ref': 'TopologyHost' | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| 'InitDatabase': { | ||
| 'Database': { | ||
| 'property_ref': 'Database' | ||
| } | ||
| }, | ||
| 'CreateReplicaTable': { | ||
| 'Database': { | ||
| 'property_ref': 'Database', | ||
| 'children': { | ||
| 'Table': { | ||
| 'property_ref': 'Table', | ||
| 'children': { | ||
| 'Column': { | ||
| 'property_ref': 'Column' | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,13 @@ | ||
| import_classes = { | ||
| 'service_implementation': [ | ||
| 'System', | ||
| 'Network', | ||
| 'NetworkTopology', | ||
| 'TopologyHost', | ||
| 'NetIPv4', | ||
| 'NetIPv6', | ||
| 'Database', | ||
| 'Table', | ||
| 'Column' | ||
| ] | ||
| } |
53 changes: 53 additions & 0 deletions
53
example/01-logical-replication/db-node-rpc/json-rpc-server.py
This file contains hidden or 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,53 @@ | ||
| import sys | ||
| import jsocket | ||
| import logging | ||
| import subprocess | ||
|
|
||
| from microesb import microesb | ||
|
|
||
| from class_reference import references as class_reference | ||
| from service_properties import service_properties | ||
| from class_mapping import class_mapping | ||
|
|
||
| logging.getLogger().addHandler( | ||
| logging.StreamHandler(sys.stdout) | ||
| ) | ||
|
|
||
| logging.getLogger().setLevel( | ||
| logging.DEBUG | ||
| ) | ||
|
|
||
|
|
||
| def get_current_ip_address(): | ||
| cmd_get_ip = 'ip -h addr show dev eth0 | grep inet | cut -d " " -f 6' | ||
| res = subprocess.run(cmd_get_ip, shell=True, capture_output=True) | ||
| raw_ip = res.stdout.strip() | ||
| raw_ip_sep = raw_ip.find(b'/') | ||
| return raw_ip[:raw_ip_sep] | ||
clauspruefer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class JSONServer(jsocket.JsonServer): | ||
|
|
||
| def __init__(self, **kwargs): | ||
| super().__init__(**kwargs) | ||
|
|
||
| def _process_message(self, call_obj): | ||
| if isinstance(call_obj, dict): | ||
| print('Call obj:{}'.format(call_obj)) | ||
| class_mapper = microesb.ClassMapper( | ||
| class_references=class_reference[call_obj['SYSServiceID']], | ||
| class_mappings=class_mapping, | ||
| class_properties=service_properties | ||
| ) | ||
| res = microesb.ServiceExecuter().execute( | ||
| class_mapper=class_mapper, | ||
| service_data=call_obj | ||
| ) | ||
| return { "Status": "ok" } | ||
| return { "Status": "error - objtype not dict()" } | ||
|
|
||
|
|
||
| server = JSONServer( | ||
| address=get_current_ip_address(), | ||
| port=64000 | ||
| ).server_loop() | ||
81 changes: 81 additions & 0 deletions
81
example/01-logical-replication/db-node-rpc/service_implementation.py
This file contains hidden or 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,81 @@ | ||
| import json | ||
| import logging | ||
|
|
||
| from microesb import microesb | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
clauspruefer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| class System(microesb.ClassHandler): | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
| def update_network_topology(self): | ||
|
|
||
| self.json_transform() | ||
|
|
||
| net_config = {} | ||
| net_config['Network'] = self.Network.json_dict | ||
| net_config['NetworkTopology'] = self.NetworkTopology.TopologyHost.json_dict | ||
|
|
||
| with open('/tmp/net-config.json', 'w')as fh: | ||
| fh.write(json.dumps(net_config)) | ||
|
|
||
|
|
||
| class Network(microesb.ClassHandler): | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
|
|
||
| class NetworkTopology(microesb.ClassHandler): | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
|
|
||
| class NetIPv4(microesb.ClassHandler): | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
|
|
||
| class NetIPv6(microesb.ClassHandler): | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
|
|
||
| class TopologyHost(microesb.MultiClassHandler): | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
|
|
||
| class Database(microesb.ClassHandler): | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
| def init_db(self): | ||
| pass | ||
|
|
||
| def create_replica_table(self): | ||
| pass | ||
|
|
||
|
|
||
| class Table(microesb.ClassHandler): | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
|
|
||
|
|
||
| class Column(microesb.MultiClassHandler): | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
| self.primary_key = False | ||
| self.name = None | ||
| self.type = None | ||
| self.default = None | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.