Elastic Distributed Database

This project aims to develop an elastic distributed database using MySQL replication to guarantee high availability and dynamic scalability and use it to serve as the backend for a multi-tier web application running TPC-W benchmark.

Configuration on single ec2

  • Config on AWS and install necessary tools on ec2(master node). password for mysql is : TigerBit!2016(default)
sudo apt-get update
sudo apt-get install -y openjdk-7-jdk ant gcc links git make
sudo apt-get install mysql-server
sudo apt-get install tomcat7

on slave nodes and candidate node, only mysql and java needs to be installed.

  • Clone repository
git clone https://github.com/jopereira/java-tpcw.git
git clone https://github.com/peterbittiger/elasticDB.git
  • Initialize Database
mysql -uroot -p < /home/ubuntu/elasticDB/tpcw/mysql.sql
  • Deployment
cd java-tpcw
patch -p1 < /home/ubuntu/elasticDB/tpcw/tpcw.patch  //  apply patch
ant dist    
sudo rm -rf /var/lib/tomcat7/webapps/tpcw*  //  not necessary for the first time
sudo cp /home/ubuntu/java-tpcw/dist/tpcw.war /var/lib/tomcat7/webapps   
ant gendb   //  populate database
sudo ant genimg //  presentation tier
  • Log in the web page
http://<ip address>:8080/tpcw/TPCW_home_interaction

Configuration on multiple ec2

Use our own laptop as client emulator, which is respond for sending different request.

  • Set root password to: 0307
sudo su
passwd
  • Change config to allow access from outside
vi /etc/ssh/sshd_config

change PermitRootLogin to yes and PasswordAuthentication to yes and then restart ssh service.

service ssh restart
  • Copy key-pairs between machines
sudo su
cd ~
ssh-keygen -t rsa
ssh-copy-id root@<ip address>

my computer copy to 4 ec2 instances, master copy to 4 ec2 instances(including itself), slaves should copy to the other 3 ec2 instances. Copying key of a to c means that c grants access to a

  • Clone repo
git clone https://github.com/peterbittiger/elasticDB.git

change the ip address in set_env.sh and run testConnection.sh to test communications

MySQL Replication Test

Run prepareMasterSlaves.sh and then log in to master node and run mysql

mysql -uroot -p
#pwd: TigerBit!2016

inside mysql enter the following commands:

mysql> use canvasjs_db;
mysql> select * from datapoints;

download related dependency for this project:

mvn dependency:resolve
mvn eclipse:eclipse

and then change ipaddress in tpcw.properties in our project:

writeQueue = <MASTER_IP>
readQueue = <MASTER_IP>,<SLAVE1_IP>,<SLAVE2_IP>
candidateQueur = <CANDIDATE_IP>

Before we run the project, we must re-run the prepareMasterSlaves.sh, which would take approximately 5 minutes. Next, run enableMonitors.sh, and we will see new tabs showing performance.

Traceback (most recent call last): File "/home/zhou/dev/MTMamba/main.py", line 188, in <module> main() File "/home/zhou/dev/MTMamba/main.py", line 112, in main train_dataset = get_train_dataset(p, train_transforms) File "/home/zhou/dev/MTMamba/utils/common_config.py", line 114, in get_train_dataset return database UnboundLocalError: local variable 'database' referenced before assignment [2025-03-05 13:41:42,391] torch.distributed.elastic.multiprocessing.api: [ERROR] failed (exitcode: 1) local_rank: 0 (pid: 46975) of binary: /home/zhou/miniconda3/envs/mamba2/bin/python3.10 Traceback (most recent call last): File "/home/zhou/miniconda3/envs/mamba2/bin/torchrun", line 8, in <module> sys.exit(main()) File "/home/zhou/miniconda3/envs/mamba2/lib/python3.10/site-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 346, in wrapper return f(*args, **kwargs) File "/home/zhou/miniconda3/envs/mamba2/lib/python3.10/site-packages/torch/distributed/run.py", line 806, in main run(args) File "/home/zhou/miniconda3/envs/mamba2/lib/python3.10/site-packages/torch/distributed/run.py", line 797, in run elastic_launch( File "/home/zhou/miniconda3/envs/mamba2/lib/python3.10/site-packages/torch/distributed/launcher/api.py", line 134, in __call__ return launch_agent(self._config, self._entrypoint, list(args)) File "/home/zhou/miniconda3/envs/mamba2/lib/python3.10/site-packages/torch/distributed/launcher/api.py", line 264, in launch_agent raise ChildFailedError( torch.distributed.elastic.multiprocessing.errors.ChildFailedError: ============================================================ main.py FAILED ------------------------------------------------------------ Failures: <NO_OTHER_FAILURES> ------------------------------------------------------------ Root Cause (first observed failure): [0]: time : 2025-03-05_13:41:42 host : f8b54d699e89 rank : 0 (local_rank: 0) exitcode : 1 (pid: 46975) error_file: <N/A> traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html ============================================================
03-08
从你提供的错误信息来看,程序抛出了 `UnboundLocalError` 异常,指出局部变量 `'database'` 在赋值前已被引用。这通常意味着在某些条件下,代码尝试访问未初始化的变量。 ### 错误分析 我们来看看具体的错误堆栈: ```plaintext File "/home/zhou/dev/MTMamba/utils/common_config.py", line 114, in get_train_dataset return database UnboundLocalError: local variable 'database' referenced before assignment ``` 这个异常发生在 `/home/zhou/dev/MTMamba/utils/common_config.py` 文件的第 114 行,在函数 `get_train_dataset` 中返回了变量 `database`,但在该行之前并未对该变量进行赋值操作。 #### 可能的原因及解决方案 1. **条件分支未能覆盖所有情况** 如果你在某个条件判断中只对部分路径进行了 `database` 的赋值,则当其他路径被执行时就会触发此错误。例如: ```python def get_train_dataset(p, transform): if some_condition: database = load_data() # 这里仅在特定条件下设置了 database return database # 当上述条件不满足时会报错 ``` 解决方案是在所有可能的情况下都给 `database` 赋初值或设置默认值: ```python def get_train_dataset(p, transform): database = None # 给出初始值 if some_condition: database = load_data() else: database = default_value # 确保总是有有效的数据库来源 return database ``` 2. **处理异步或其他可能导致失败的操作** 若加载数据的过程涉及到文件读取、网络请求等可能出现异常的情况,应加入适当的异常捕获机制,并给出合理的替代措施。 ```python try: database = complex_operation_to_load_database() except Exception as e: print(f"Failed to load data due to {str(e)}") database = fallback_method_or_default_value() finally: return database ``` 3. **检查配置是否正确** 检查传递给 `get_train_dataset()` 函数的参数 `p` 和 `train_transforms` 是否按预期工作,有时问题可能是由于输入的数据源不存在或是格式不对导致无法成功创建 `database` 对象而引起的。 ### 下一步行动建议 根据上面提到的可能性逐一排查原因,重点放在确保无论哪种情况下都能正常地生成并返回 `database` 变量上。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值