Skip to content

Commit 7fe22f8

Browse files
committed
Initial commit
0 parents  commit 7fe22f8

12 files changed

+1545
-0
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
database
2+
node_modules
3+
test.http

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
dataset/

Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM node:20-alpine
2+
RUN apk add g++ make py3-pip
3+
WORKDIR /usr/code
4+
COPY package*.json ./
5+
RUN npm install --production
6+
COPY . .
7+
EXPOSE 5000
8+
CMD ["npm", "run", "start:prod"]

database/primary.sql

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
CREATE DATABASE IF NOT EXISTS primarydb;
3+
4+
USE primarydb;
5+
6+
DROP TABLE IF EXISTS posts;
7+
8+
-- SET GLOBAL local_infile = true;
9+
10+
CREATE TABLE posts (Id INTEGER, CreationDate DATE, Score Integer, ViewCount INTEGER, Body TEXT, OwnerUserId Integer, LastEditorUserId Integer, LastEditDate DATE, LastActivityDate DATE, Title TEXT, Tags TEXT, AnswerCount Integer, CommentCount Integer, ClosedDate Date, ContentLicense TEXT);
11+
12+
13+
14+
LOAD XML INFILE '/var/lib/mysql-files/dataset/Posts.xml' INTO TABLE posts ROWS IDENTIFIED BY '<row>';
15+
16+
17+
-- SET GLOBAL local_infile = false;
18+

database/shard0.sql

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
CREATE DATABASE IF NOT EXISTS shard0db;
3+
4+
USE shard0db;
5+
6+
DROP TABLE IF EXISTS posts;
7+
8+
-- SET GLOBAL local_infile = true;
9+
10+
CREATE TABLE posts (Id INTEGER, CreationDate DATE, Score Integer, ViewCount INTEGER, Body TEXT, OwnerUserId Integer, LastEditorUserId Integer, LastEditDate DATE, LastActivityDate DATE, Title TEXT, Tags TEXT, AnswerCount Integer, CommentCount Integer, ClosedDate Date, ContentLicense TEXT);
11+
12+
13+
LOAD XML INFILE '/var/lib/mysql-files/dataset/Posts.xml' INTO TABLE posts ROWS IDENTIFIED BY '<row>';
14+
15+
16+
DELETE FROM posts WHERE MOD(posts.Id, 3) != 0;
17+

database/shard1.sql

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
CREATE DATABASE IF NOT EXISTS shard1db;
3+
4+
USE shard1db;
5+
6+
DROP TABLE IF EXISTS posts;
7+
8+
-- SET GLOBAL local_infile = true;
9+
10+
CREATE TABLE posts (Id INTEGER, CreationDate DATE, Score Integer, ViewCount INTEGER, Body TEXT, OwnerUserId Integer, LastEditorUserId Integer, LastEditDate DATE, LastActivityDate DATE, Title TEXT, Tags TEXT, AnswerCount Integer, CommentCount Integer, ClosedDate Date, ContentLicense TEXT);
11+
12+
13+
LOAD XML INFILE '/var/lib/mysql-files/dataset/Posts.xml' INTO TABLE posts ROWS IDENTIFIED BY '<row>';
14+
15+
16+
DELETE FROM posts WHERE MOD(posts.Id + 1, 3) != 0;
17+

database/shard2.sql

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
CREATE DATABASE IF NOT EXISTS shard2db;
3+
4+
USE shard2db;
5+
6+
DROP TABLE IF EXISTS posts;
7+
8+
-- SET GLOBAL local_infile = true;
9+
10+
CREATE TABLE posts (Id INTEGER, CreationDate DATE, Score Integer, ViewCount INTEGER, Body TEXT, OwnerUserId Integer, LastEditorUserId Integer, LastEditDate DATE, LastActivityDate DATE, Title TEXT, Tags TEXT, AnswerCount Integer, CommentCount Integer, ClosedDate Date, ContentLicense TEXT);
11+
12+
13+
LOAD XML INFILE '/var/lib/mysql-files/dataset/Posts.xml' INTO TABLE posts ROWS IDENTIFIED BY '<row>';
14+
15+
16+
DELETE FROM posts WHERE MOD(posts.Id + 2, 3) != 0;
17+

docker-compose.yaml

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
services:
2+
primarydb:
3+
image: mysql:8.0
4+
container_name: primarydb_container
5+
command:
6+
- "--default-authentication-plugin=mysql_native_password"
7+
- "--local-infile=1"
8+
restart: always
9+
volumes:
10+
# Copy Dataset
11+
- ./dataset/Posts.xml:/var/lib/mysql-files/dataset/Posts.xml
12+
# Run SQL file on init
13+
- ./database/primary.sql:/docker-entrypoint-initdb.d/0_init.sql
14+
# Persist data
15+
- $HOME/databaseP:/var/lib/mysql
16+
ports:
17+
- 3306:3306
18+
environment:
19+
MYSQL_DATABASE: primarydb
20+
MYSQL_USER: admin
21+
MYSQL_PASSWORD: password
22+
MYSQL_ROOT_PASSWORD: password
23+
MYSQL_TCP_PORT: 3306
24+
SERVICE_NAME: primarydb
25+
networks:
26+
- dbnet
27+
shard0db:
28+
image: mysql:8.0
29+
container_name: shard0_container
30+
command:
31+
- "--default-authentication-plugin=mysql_native_password"
32+
- "--local-infile=1"
33+
restart: always
34+
volumes:
35+
# Copy Dataset
36+
- ./dataset/Posts.xml:/var/lib/mysql-files/dataset/Posts.xml
37+
# Run SQL file on init
38+
- ./database/shard0.sql:/docker-entrypoint-initdb.d/0_init.sql
39+
# Persist data
40+
- $HOME/databaseS0:/var/lib/mysql
41+
ports:
42+
- 4000:4000
43+
environment:
44+
MYSQL_DATABASE: shard0db
45+
MYSQL_USER: admin
46+
MYSQL_PASSWORD: password
47+
MYSQL_ROOT_PASSWORD: password
48+
MYSQL_TCP_PORT: 4000
49+
SERVICE_NAME: shard0db
50+
networks:
51+
- dbnet
52+
shard1db:
53+
image: mysql:8.0
54+
container_name: shard1_container
55+
command:
56+
- "--default-authentication-plugin=mysql_native_password"
57+
- "--local-infile=1"
58+
restart: always
59+
volumes:
60+
# Copy Dataset
61+
- ./dataset/Posts.xml:/var/lib/mysql-files/dataset/Posts.xml
62+
# Run SQL file on init
63+
- ./database/shard1.sql:/docker-entrypoint-initdb.d/0_init.sql
64+
# Persist data
65+
- $HOME/databaseS1:/var/lib/mysql
66+
ports:
67+
- 4001:4001
68+
environment:
69+
MYSQL_DATABASE: shard1db
70+
MYSQL_USER: admin
71+
MYSQL_PASSWORD: password
72+
MYSQL_ROOT_PASSWORD: password
73+
MYSQL_TCP_PORT: 4001
74+
SERVICE_NAME: shard1db
75+
networks:
76+
- dbnet
77+
shard2db:
78+
image: mysql:8.0
79+
container_name: shard2_container
80+
command:
81+
- "--default-authentication-plugin=mysql_native_password"
82+
- "--local-infile=1"
83+
restart: always
84+
volumes:
85+
# Copy Dataset
86+
- ./dataset/Posts.xml:/var/lib/mysql-files/dataset/Posts.xml
87+
# Run SQL file on init
88+
- ./database/shard2.sql:/docker-entrypoint-initdb.d/0_init.sql
89+
# Persist data
90+
- $HOME/databaseS2:/var/lib/mysql
91+
ports:
92+
- 4002:4002
93+
environment:
94+
MYSQL_DATABASE: shard2db
95+
MYSQL_USER: admin
96+
MYSQL_PASSWORD: password
97+
MYSQL_ROOT_PASSWORD: password
98+
MYSQL_TCP_PORT: 4002
99+
SERVICE_NAME: shard2db
100+
networks:
101+
- dbnet
102+
103+
# nodeapp:
104+
# container_name: nodecontainer
105+
# build: .
106+
# ports:
107+
# - '5000:5000'
108+
# expose:
109+
# - 5000
110+
# volumes:
111+
# - $HOME/nodeapp:/app
112+
# environment:
113+
# PRIMARYDB_HOST: dbnet
114+
# PRIMARYDB_PORT: 3306
115+
# PRIMARYDB_NAME: 'primarydb'
116+
# SHARD0_HOST: dbnet
117+
# SHARD0_PORT: 4000
118+
# SHARD0_NAME: 'shard0db'
119+
# SHARD1_HOST: dbnet
120+
# SHARD1_PORT: 4001
121+
# SHARD1_NAME: 'shard1db'
122+
# SHARD2_HOST: dbnet
123+
# SHARD2_PORT: 4002
124+
# SHARD2_NAME: 'shard2db'
125+
# SERVICE_NAME: nodeapp
126+
# depends_on:
127+
# - primarydb
128+
# - shard0db
129+
# - shard1db
130+
# - shard2db
131+
# networks:
132+
# - dbnet
133+
networks:
134+
dbnet:
135+
driver: bridge

0 commit comments

Comments
 (0)