summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Kobert <dennis@kobert.dev>2020-02-09 23:06:13 +0000
committerDennis Kobert <dennis@kobert.dev>2020-02-09 23:06:13 +0000
commit10ea9b412d0e9bc3152be8138811b2f473c48c67 (patch)
tree92d4c5d203e6c7f21e3ba4c8f22d12da461f6381
parent102a39ffc870537a45113f01f7c3ea1ca03fa1bc (diff)
latest Noria try
-rw-r--r--Cargo.toml6
-rw-r--r--docker/docker-compose.yml39
-rw-r--r--src/main.rs40
3 files changed, 63 insertions, 22 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 6f3a9d5..9ebe69f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,4 +10,8 @@ edition = "2018"
rspotify = "0.7"
rocket = "0.4"
lazy_static = { version = "1.4"}
-noria = {git="https://github.com/mit-pdos/noria"}
+#noria = { git = "https://github.com/mit-pdos/noria" }
+noria = { path = "noria/noria" }
+noria-server = { path = "noria/noria-server" }
+futures = "0.3"
+tokio = { version = "0.2", features = ["full"] }
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index 477176b..209f953 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -14,26 +14,35 @@ services:
- hostnet
depends_on:
- track_db
- - zookeeper
+ # - zookeeper
track_db:
- image: noria
- build:
- context: ..
- dockerfile: docker/noria/Dockerfile
- #volumes:
- #- db:/srv/noria
+ image: postgresql
+ container_name: track_db
networks:
- database
- depends_on:
- - zookeeper
+ environment:
+ POSTGRES_PASSWORD: example
+
+ volumes: ./data:/var/lib/postgresql/data
+ #track_db:
+ #image: noria
+ # build:
+ #context: ..
+ #dockerfile: docker/noria/Dockerfile
+ #volumes:
+ #- db:/srv/noria
+ #networks:
+ #- database
+ # depends_on:
+ #- zookeeper
#volumes:
#db: {}
- zookeeper:
- image: 'bitnami/zookeeper:latest'
- networks:
- - database
- environment:
- ALLOW_ANONYMOUS_LOGIN: "yes"
+ #zookeeper:
+ #image: 'bitnami/zookeeper:latest'
+ #networks:
+ #- database
+ #environment:
+ #ALLOW_ANONYMOUS_LOGIN: "yes"
networks:
database:
diff --git a/src/main.rs b/src/main.rs
index 16e7bbd..bfd53b8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,6 +8,7 @@ use rspotify::spotify::util::get_token;
mod serve;
+//#[tokio::main]
fn main() {
// Set client_id and client_secret in .env file or
// export CLIENT_ID="your client_id"
@@ -22,16 +23,37 @@ fn main() {
// .build();
//
// looking up article 42 should yield the article we inserted with a vote count of 1
- init();
+ let mut rt = tokio::runtime::Builder::new()
+ .enable_all()
+ .threaded_scheduler()
+ .thread_name("voter")
+ .build()
+ .unwrap();
+
+ let mut db = rt
+ .block_on(noria::ControllerHandle::from_zk("127.0.0.1:2181"))
+ .unwrap();
+ println!("test");
+ rt.block_on(db.install_recipe(
+ "
+ CREATE TABLE Article (aid int, title varchar(255), url text, PRIMARY KEY(aid));
+ CREATE TABLE Vote (aid int, uid int);
+",
+ ))
+ .unwrap();
+ println!("staring_init");
+ let init = init();
rocket::ignite()
.mount("/", routes![serve::token, serve::get_tracks])
.launch();
+ rt.block_on(init);
}
-
async fn init() {
- let mut db = noria::ControllerHandle::from_zk("127.0.0.1:2181").await.unwrap();
+ let mut db = noria::ControllerHandle::from_zk("127.0.0.1:2181")
+ .await
+ .unwrap();
//db.ready();
//println!("test {:?}", db.url());
@@ -40,7 +62,9 @@ async fn init() {
CREATE TABLE Article (aid int, title varchar(255), url text, PRIMARY KEY(aid));
CREATE TABLE Vote (aid int, uid int);
",
- );
+ )
+ .await
+ .unwrap();
println!("test");
// we can then get handles that let us insert into the new tables
let mut article = db.table("Article").await.unwrap();
@@ -52,7 +76,8 @@ async fn init() {
let url = "https://pdos.csail.mit.edu";
article
.insert(vec![aid.into(), title.into(), url.into()])
- .await.unwrap();
+ .await
+ .unwrap();
// and then vote for it
vote.insert(vec![aid.into(), 1.into()]).await.unwrap();
@@ -68,7 +93,9 @@ async fn init() {
SELECT Article.aid, title, url, VoteCount.votes AS votes \
FROM Article LEFT JOIN VoteCount ON (Article.aid = VoteCount.aid) \
WHERE Article.aid = ?;",
- );
+ )
+ .await
+ .unwrap();
// and then get handles that let us execute those queries to fetch their results
let mut awvc = db.view("ArticleWithVoteCount").await.unwrap();
@@ -82,4 +109,5 @@ async fn init() {
1.into()
]]
);
+ println!("init done");
}