Skip to content
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

Failover 3 #306

Open
wants to merge 100 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
4ed7231
python 3 upgrade;few code semantics;new py3 bytes vs all string in py2
Dec 12, 2022
d4ec9d3
python2->python3 migration;sqlite->postgresql migration
Dec 13, 2022
fd8ca46
allow NLB health checks without Bad Descriptor exceptions
Dec 13, 2022
dc2eeb0
remove NLB health cheaks disconnected server prints from client
Dec 13, 2022
fcc1eb3
disable auth
Dec 20, 2022
9a44466
disable auth
Dec 20, 2022
cbfeb64
disable auth
Dec 20, 2022
154af52
disable auth
Dec 20, 2022
8e8d1ac
disable auth
Dec 20, 2022
ca25717
disable auth
Dec 21, 2022
f615798
disable auth
Dec 21, 2022
0ffd838
disable auth
Dec 21, 2022
6af174f
disable auth
Dec 21, 2022
f84c472
disable auth
Dec 21, 2022
835f6e9
disable auth
Dec 21, 2022
c63bd1b
disable auth
Dec 21, 2022
4a7adfa
disable auth
Dec 21, 2022
e2646e3
disable auth
Dec 21, 2022
5c06874
disable auth
Dec 21, 2022
faecfed
disable auth
Dec 21, 2022
662a481
disable auth
Dec 21, 2022
70ec4a7
disable auth
Dec 21, 2022
2b02dcb
add user_id to block
Dec 21, 2022
e7c5cce
add user_id to block
Dec 21, 2022
39bca8c
add user_id to block
Dec 21, 2022
8c71cdf
add user_id to block
Dec 21, 2022
20dee3c
add user_id to block
Dec 21, 2022
e403da7
add user_id to block
Dec 21, 2022
ca246ab
add user_id to block
Dec 21, 2022
55f1b45
add user_id to block
Dec 21, 2022
d70a7aa
add user_id to block
Dec 22, 2022
dc31263
add user_id to block
Dec 22, 2022
2578d97
add user_id to block
Dec 22, 2022
aafc55c
add user_id to block
Dec 22, 2022
f674364
add user_id to block
Dec 22, 2022
439d047
bob the builder
Dec 22, 2022
ab523f3
bob the builder
Dec 22, 2022
7b52ab0
bob the builder
Dec 23, 2022
84700c8
bob the builder
Dec 23, 2022
c428f8a
build world
Dec 23, 2022
66ff088
spawn point
Dec 23, 2022
fa17103
spawn point
Dec 23, 2022
3b073e1
spawn point
Dec 23, 2022
d47cb88
agones/craft
Dec 23, 2022
9a56dde
agones
Dec 23, 2022
16765a9
agones
Dec 23, 2022
f510111
agones
Dec 23, 2022
8f1b73e
agones
Dec 23, 2022
a59bc3c
agones
Dec 23, 2022
01ad890
agones
Dec 23, 2022
94bc8ab
agones
Dec 23, 2022
e5c7432
agones
Dec 23, 2022
c4a00bd
agones
Dec 23, 2022
2ac8b0a
agones
Dec 23, 2022
26f09a6
agones
Dec 23, 2022
84a7868
agones
Dec 24, 2022
fd53a2f
agones
Dec 24, 2022
1d83c59
agones
Dec 24, 2022
805b5d8
agones
Dec 24, 2022
01a8295
agones
Dec 24, 2022
ab98955
agones
Dec 24, 2022
6bef3e2
agones
Dec 24, 2022
8f356e9
agones
Dec 24, 2022
6d623be
agones
Dec 24, 2022
5dd74ab
agones
Dec 24, 2022
2084341
agones
Dec 24, 2022
db787dd
agones
Dec 24, 2022
9bd122f
agones
Dec 24, 2022
05c24df
auth
Dec 25, 2022
0a569a7
auth
Dec 25, 2022
e0bc666
auth
Dec 25, 2022
c4de1cb
auth
Dec 25, 2022
8a8dab5
auth
Dec 25, 2022
5f46544
auth
Dec 25, 2022
1de9e27
auth
Dec 25, 2022
87ae38c
auth
Dec 25, 2022
b9d3d3a
auth
Dec 25, 2022
15bf7b1
auth
Dec 25, 2022
1f170c0
auth
Dec 25, 2022
a70fe8a
auth
Dec 25, 2022
47fe63b
auth
Dec 25, 2022
5910e2f
auth
Dec 25, 2022
afca761
auth
Dec 25, 2022
4c5b64a
auth
Dec 25, 2022
eeea2d3
auth
Dec 25, 2022
c69f16a
auth
Dec 25, 2022
860670f
auth
Dec 25, 2022
436650b
auth
Dec 25, 2022
4884d37
auth
Dec 25, 2022
2286d7f
auth
Dec 25, 2022
ca82963
auth
Dec 25, 2022
1866242
auth
Dec 25, 2022
032daf2
auth
Dec 27, 2022
5b99bbf
auth
Dec 27, 2022
0b7f0d1
auth
Dec 27, 2022
8dd6752
auth
Dec 27, 2022
3cbcf55
auth
Dec 27, 2022
0224c4a
failover
Dec 27, 2022
dcff75b
failover
Dec 27, 2022
56d2cc1
failover
Dec 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 139 additions & 62 deletions builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import socket
import sqlite3
import sys
import os
import time
import boto3

DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORT = 4080
QUEUE_URL = os.environ['SQS_CHECKPOINT_QUEUE_URL']
DEFAULT_HOST = os.environ['CRAFT_HOST']
DEFAULT_PORT = os.environ['CRAFT_PORT']

EMPTY = 0
GRASS = 1
Expand Down Expand Up @@ -45,6 +49,43 @@
(0.5, 0.5, 0.5),
]

sqs=boto3.client('sqs')

def store_checkpoint(checkpoint):
response=sqs.send_message(
QueueUrl=QUEUE_URL,
DelaySeconds=10,
MessageBody=(checkpoint)
)
print(response['MessageId'])
sys.stdout.flush()

def pull_checkpoint():
response=sqs.receive_message(
QueueUrl=QUEUE_URL,
MaxNumberOfMessages=1,
VisibilityTimeout=0,
WaitTimeSeconds=0
)
print('in pull_checkpoint:response:%s'%response)
if 'Messages' in response.keys():
message=response['Messages'][0]
receipt_handle=message['ReceiptHandle']
last_checkpoint=message['Body']
print('in pull_checkpoint:last_checkpoint %s' % last_checkpoint)
sys.stdout.flush()

sqs.delete_message(
QueueUrl=QUEUE_URL,
ReceiptHandle=receipt_handle
)
print('in pull_checkpoint:Received and deleted message:%s'%message)
sys.stdout.flush()
else:
print('in pull_checkpoint: no previous checkpoints in queue')
last_checkpoint="1"
return last_checkpoint

def sphere(cx, cy, cz, r, fill=False, fx=False, fy=False, fz=False):
result = set()
for x in range(cx - r, cx + r + 1):
Expand Down Expand Up @@ -143,7 +184,7 @@ class Client(object):
def __init__(self, host, port):
self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.conn.connect((host, port))
self.authenticate()
#self.authenticate()
def authenticate(self):
username, identity_token = get_identity()
url = 'https://craft.michaelfogleman.com/api/1/identity'
Expand All @@ -154,11 +195,27 @@ def authenticate(self):
response = requests.post(url, data=payload)
if response.status_code == 200 and response.text.isalnum():
access_token = response.text
self.conn.sendall('A,%s,%s\n' % (username, access_token))
buf=b''
string='A,%s,%s\n' % (username, access_token)
buf=bytes(string,'utf-8')
self.conn.sendall(buf)
print(buf)
sys.stdout.flush()
else:
raise Exception('Failed to authenticate.')
def set_block(self, x, y, z, w):
self.conn.sendall('B,%d,%d,%d,%d\n' % (x, y, z, w))
buf=b''
string='B,%d,%d,%d,%d\n' % (x, y, z, w)
buf=bytes(string,'utf-8')
try:
r=self.conn.sendall(buf)
print('buf={},r={}'.format(buf,r))
sys.stdout.flush()
time.sleep(1)
except Exception as error:
print('in set_block:error:',error)
sys.stdout.flush()
#self.conn.sendall('B,%d,%d,%d,%d\n' % (x, y, z, w))
def set_blocks(self, blocks, w):
key = lambda block: (block[1], block[0], block[2])
for x, y, z in sorted(blocks, key=key):
Expand Down Expand Up @@ -186,63 +243,83 @@ def get_client():
return client

def main():
client = get_client()
set_block = client.set_block
set_blocks = client.set_blocks
# set_blocks(circle_y(0, 32, 0, 16, True), STONE)
# set_blocks(circle_y(0, 33, 0, 16), BRICK)
# set_blocks(cuboid(-1, 1, 1, 31, -1, 1), CEMENT)
# set_blocks(cuboid(-1024, 1024, 32, 32, -3, 3), STONE)
# set_blocks(cuboid(-3, 3, 32, 32, -1024, 1024), STONE)
# set_blocks(cuboid(-1024, 1024, 33, 33, -3, -3), BRICK)
# set_blocks(cuboid(-1024, 1024, 33, 33, 3, 3), BRICK)
# set_blocks(cuboid(-3, -3, 33, 33, -1024, 1024), BRICK)
# set_blocks(cuboid(3, 3, 33, 33, -1024, 1024), BRICK)
# set_blocks(sphere(0, 32, 0, 16), GLASS)
# for y in range(1, 32):
# set_blocks(circle_y(0, y, 0, 4, True), CEMENT)
# set_blocks(circle_x(16, 33, 0, 3), BRICK)
# set_blocks(circle_x(-16, 33, 0, 3), BRICK)
# set_blocks(circle_z(0, 33, 16, 3), BRICK)
# set_blocks(circle_z(0, 33, -16, 3), BRICK)
# for x in range(0, 1024, 32):
# set_blocks(cuboid(x - 1, x + 1, 31, 32, -1, 1), CEMENT)
# set_blocks(cuboid(-x - 1, -x + 1, 31, 32, -1, 1), CEMENT)
# set_blocks(cuboid(x, x, 1, 32, -1, 1), CEMENT)
# set_blocks(cuboid(-x, -x, 1, 32, -1, 1), CEMENT)
# for z in range(0, 1024, 32):
# set_blocks(cuboid(-1, 1, 31, 32, z - 1, z + 1), CEMENT)
# set_blocks(cuboid(-1, 1, 31, 32, -z - 1, -z + 1), CEMENT)
# set_blocks(cuboid(-1, 1, 1, 32, z, z), CEMENT)
# set_blocks(cuboid(-1, 1, 1, 32, -z, -z), CEMENT)
# for x in range(0, 1024, 8):
# set_block(x, 32, 0, CEMENT)
# set_block(-x, 32, 0, CEMENT)
# for z in range(0, 1024, 8):
# set_block(0, 32, z, CEMENT)
# set_block(0, 32, -z, CEMENT)
# set_blocks(pyramid(32, 32+64-1, 12, 32, 32+64-1), COBBLE)
# outer = circle_y(0, 11, 0, 176 + 3, True)
# inner = circle_y(0, 11, 0, 176 - 3, True)
# set_blocks(outer - inner, STONE)
# a = sphere(-32, 48, -32, 24, True)
# b = sphere(-24, 40, -24, 24, True)
# set_blocks(a - b, PLANK)
# set_blocks(cylinder_x(-64, 64, 32, 0, 8), STONE)
# data = [
# '...............................',
# '..xxx..xxxx...xxx..xxxxx.xxxxx.',
# '.x...x.x...x.x...x.x.......x...',
# '.x.....xxxx..xxxxx.xxx.....x...',
# '.x...x.x..x..x...x.x.......x...',
# '..xxx..x...x.x...x.x.......x...',
# '...............................',
# ]
# lookup = {
# 'x': STONE,
# '.': PLANK,
# }
# client.bitmap(0, 32, 32, (1, 0, 0), (0, -1, 0), data, lookup)
client = get_client()
set_block = client.set_block
set_blocks = client.set_blocks
#store_checkpoint('1')
last_checkpoint=pull_checkpoint()
print('in main:lastcheckpoint ',last_checkpoint)
match last_checkpoint:
case '1':
set_blocks(circle_y(0, 32, 0, 16, True), STONE)
set_blocks(circle_y(0, 33, 0, 16), BRICK)
set_blocks(cuboid(-1, 1, 1, 31, -1, 1), CEMENT)
set_blocks(cuboid(-1024, 1024, 32, 32, -3, 3), STONE)
set_blocks(cuboid(-3, 3, 32, 32, -1024, 1024), STONE)
set_blocks(cuboid(-1024, 1024, 33, 33, -3, -3), BRICK)
set_blocks(cuboid(-1024, 1024, 33, 33, 3, 3), BRICK)
set_blocks(cuboid(-3, -3, 33, 33, -1024, 1024), BRICK)
set_blocks(cuboid(3, 3, 33, 33, -1024, 1024), BRICK)
set_blocks(sphere(0, 32, 0, 16), GLASS)
store_checkpoint('1')
case '2':
for y in range(1, 32):
set_blocks(circle_y(0, y, 0, 4, True), CEMENT)
set_blocks(circle_x(16, 33, 0, 3), BRICK)
set_blocks(circle_x(-16, 33, 0, 3), BRICK)
set_blocks(circle_z(0, 33, 16, 3), BRICK)
set_blocks(circle_z(0, 33, -16, 3), BRICK)
store_checkpoint('2')
case '3':
for x in range(0, 1024, 32):
set_blocks(cuboid(x - 1, x + 1, 31, 32, -1, 1), CEMENT)
set_blocks(cuboid(-x - 1, -x + 1, 31, 32, -1, 1), CEMENT)
set_blocks(cuboid(x, x, 1, 32, -1, 1), CEMENT)
set_blocks(cuboid(-x, -x, 1, 32, -1, 1), CEMENT)
store_checkpoint('3')
case '4':
for z in range(0, 1024, 32):
set_blocks(cuboid(-1, 1, 31, 32, z - 1, z + 1), CEMENT)
set_blocks(cuboid(-1, 1, 31, 32, -z - 1, -z + 1), CEMENT)
set_blocks(cuboid(-1, 1, 1, 32, z, z), CEMENT)
set_blocks(cuboid(-1, 1, 1, 32, -z, -z), CEMENT)
store_checkpoint('4')
case '5':
for x in range(0, 1024, 8):
set_block(x, 32, 0, CEMENT)
set_block(-x, 32, 0, CEMENT)
store_checkpoint('5')
case '6':
for z in range(0, 1024, 8):
set_block(0, 32, z, CEMENT)
set_block(0, 32, -z, CEMENT)
store_checkpoint('6')
case '7':
set_blocks(pyramid(32, 32+64-1, 12, 32, 32+64-1), COBBLE)
outer = circle_y(0, 11, 0, 176 + 3, True)
inner = circle_y(0, 11, 0, 176 - 3, True)
set_blocks(outer - inner, STONE)
a = sphere(-32, 48, -32, 24, True)
b = sphere(-24, 40, -24, 24, True)
set_blocks(a - b, PLANK)
set_blocks(cylinder_x(-64, 64, 32, 0, 8), STONE)
store_checkpoint('7')
case '8':
data = [
'...............................',
'..xxx..xxxx...xxx..xxxxx.xxxxx.',
'.x...x.x...x.x...x.x.......x...',
'.x.....xxxx..xxxxx.xxx.....x...',
'.x...x.x..x..x...x.x.......x...',
'..xxx..x...x.x...x.x.......x...',
'...............................',
]
lookup = {
'x': STONE,
'.': PLANK,
}
client.bitmap(0, 32, 32, (1, 0, 0), (0, -1, 0), data, lookup)
store_checkpoint('8')

if __name__ == '__main__':
main()
Binary file added cache.craft.yahav.sa.aws.dev.4080.db-journal
Binary file not shown.
64 changes: 64 additions & 0 deletions create_db_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
create SEQUENCE block_rowid start 1;
create SEQUENCE light_rowid start 1;
create SEQUENCE sign_rowid start 1;
create SEQUENCE block_history_rowid start 1;

create table block (
rowid bigint default nextval('public.block_rowid'::regclass) primary key,
updated_at timestamp,
user_id varchar(64) not null,
p int not null,
q int not null,
x int not null,
y int not null,
z int not null,
w int not null
);
alter table block add constraint unique_block_pqxyz unique (p,q,x,y,z);

create table if not exists light (
rowid bigint default nextval('public.light_rowid'::regclass) primary key,
p int not null,
q int not null,
x int not null,
y int not null,
z int not null,
w int not null
);
create unique index if not exists light_pqxyz_idx on light (p, q, x, y, z);

create table if not exists sign (
rowid bigint default nextval('public.sign_rowid'::regclass) primary key,
p int not null,
q int not null,
x int not null,
y int not null,
z int not null,
face int not null,
text text not null
);
create index if not exists sign_pq_idx on sign (p, q);

create unique index if not exists sign_xyzface_idx on sign (x, y, z, face);

create table if not exists block_history (
rowid bigint default nextval('public.block_history_rowid'::regclass),
created_at timestamp,
user_id varchar(64) not null,
p int not null,
q int not null,
x int not null,
y int not null,
z int not null,
w int not null,
primary key (rowid,created_at)
) partition by range (created_at);

CREATE SCHEMA partman;
CREATE EXTENSION pg_partman WITH SCHEMA partman;

SELECT partman.create_parent( p_parent_table => 'public.block_history',
p_control => 'created_at',
p_type => 'native',
p_interval=> 'monthly',
p_premake => 24);
29 changes: 29 additions & 0 deletions deps/glfw/src/glfw3Config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# - Config file for the glfw3 package
# It defines the following variables
# GLFW3_INCLUDE_DIR, the path where GLFW headers are located
# GLFW3_LIBRARY_DIR, folder in which the GLFW library is located
# GLFW3_LIBRARY, library to link against to use GLFW

set(GLFW3_VERSION "3.1.2")


####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was glfw3Config.cmake.in ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

macro(set_and_check _var _file)
set(${_var} "${_file}")
if(NOT EXISTS "${_file}")
message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
endif()
endmacro()

####################################################################################

set_and_check(GLFW3_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
set_and_check(GLFW3_LIBRARY_DIR "${PACKAGE_PREFIX_DIR}/lib")

find_library(GLFW3_LIBRARY "glfw3" HINTS ${GLFW3_LIBRARY_DIR})

Loading