Skip to content
This repository was archived by the owner on Jul 11, 2021. It is now read-only.

Commit db6f852

Browse files
committed
fix merge
2 parents 2aa3fec + ee3c7fa commit db6f852

File tree

6 files changed

+198
-109
lines changed

6 files changed

+198
-109
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM redis:latest
22

33
# RUN apk update; apk add libgcc_s.so.1
44

5-
COPY /target/release/libredis_sql.so /usr/local/lib
5+
COPY releases/0.9.1/redisql_v0.9.1_x86_64.so /usr/local/lib
66

77
EXPOSE 6379
88

README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ RediSQL is the Fast, in-memory, SQL engine with batteries included.
44

55
It provides several benefits for your application.
66

7-
1. Fast, it can top up to 130k inserts per *seconds*.
7+
1. Fast, it can top up to 130k inserts per *second*.
88
2. Familiar, it works with standard SQL, no weird dialect or syntax to learn.
99
3. Easy to Operate, it is based on Redis, just start the standard Redis binary and and pass the RediSQL binary.
1010
4. Easy to Use, being based on Redis there are already bindings for any language.
@@ -16,55 +16,55 @@ There are several use cases for RediSQL.
1616
### RediSQL to store Transient Data
1717

1818
RediSQL is wonderful for transient data.
19-
With supports for lightweights DBs you can just store all the data that are important now, and trash them all together as soon as they are not necessary anymore.
19+
With supports for lightweights DBs, you can just store all the data that are important now, and trash them all together as soon as they are not necessary anymore.
2020

2121
### RediSQL as main database
2222

23-
The product is stable, it does not loose data and you can store the data into regular files to gain in persistency.
24-
Moreover RediSQL support all the persistency features of Redis, hence RDB and AOF are both fully supported.
23+
The product is stable, it does not lose data.
24+
Moreover RediSQL supports all the persistency features of Redis, hence RDB and AOF are both fully supported.
2525

2626
## Much more to explore...
2727

28-
There are a lot of features in RediSQL that is worth to explore more, here a short excerpt of those features.
28+
There are a lot of features in RediSQL that are worth exploring more. Here are short explanations of those features.
2929

3030
#### Lightweight DBs
3131

32-
RediSQL provides you with lightweight in memory databases.
33-
It could completely shift your architecture, indeed you could thing to create a new isolated database each day, or for every tenant of your application or even for each of your users.
32+
RediSQL provides you with lightweight in-memory databases.
33+
It could completely shift your architecture. For example, you could create a new isolated database each day, one for each application tenant, or even one per user.
3434

3535
#### On disk storage
3636

37-
While RediSQL focus on in-memory database, it can also store data in a regular file. Of course this makes operations slower, but it allow to reach a level of persistency and safeness of data on pair with regular databases as Postgres or MySQL.
37+
While RediSQL focuses on in-memory database, it can also store data in a regular file. Of course this makes operations slower, but it allows RediSQL to reach a level of data persistency on par with incumbent databases such as Postgres or MySQL.
3838

3939
#### Copy of DBs
4040

41-
With the concept of lightweight databases it become necessary to have a way to duplicate your database.
41+
With the concept of lightweight databases, it becomes necessary to have a way to duplicate your database.
4242
Indeed it is possible to copy a database into another one.
43-
This allow several interesting patterns.
44-
For example you could copy an in-memory database into a file-backed database and then ship the file for storage or other analysis.
43+
This allows several interesting patterns.
44+
For example, you could copy an in-memory database into a file-backed database and then ship the file for storage or other analysis.
4545
Another pattern would be to copy a heavy read database into another for load balancing reasons.
4646
Moreover you may use the copy function to keep a "base-database" to grow when new data comes in.
4747

4848
#### Directly expose the DB to users
4949

50-
With the ability to create several lightweight databases and the capability to copy those database, you could directly expose directly the databases to the final users instead of exposing a set of API that you would need to maintain.
50+
With the ability to create several lightweight databases, and the capability to copy those database, you could directly expose the databases to the end users instead of exposing an API that you would need to maintain.
5151
Just load all the data that the user may need into a RediSQL database, document the tables that are available, and give access to it to the users.
5252
They will write their own API without waiting on you.
5353

5454
#### Stream and cache query results
5555

56-
RediSQL allow to store the results of queries into a Redis Stream.
57-
This allow different clients to consume part of the result, or to delay the consuption of a result.
58-
Moreover it allow to cache the result of expensive queries into Redis Streams and consume them over and over again.
56+
RediSQL can also store results of queries into a Redis Streams.
57+
This allows different clients to consume part of the result, or to delay the consuption of a result.
58+
Moreover, it allows caching the result of expensive queries as Redis Streams to consume them over and over again.
5959

6060
#### Complete JSON support
6161

62-
JSON is the de-facto standard to share data between application, indeed RediSQL exploit the JSON1 module of SQLite to bring you the capability to easy and quickly manage JSON data inside SQL statements and tables.
63-
In RediSQL you are able to manipulate JSON in all the possible way.
62+
JSON is the de-facto standard for sharing data between applications. RediSQL exploits the JSON1 module of SQLite to bring that capability to easy and quickly manage JSON data inside SQL statements and tables.
63+
In RediSQL you are able to manipulate JSON in every standard way.
6464

6565
#### Full text search support
6666

67-
RediSQL fully supports also the FTS{3,4,5} engine in SQLite giving you a full text engine at your fingertip.
67+
RediSQL fully supports also the FTS{3,4,5} engine from SQLite, giving you a full text engine at your fingertip.
6868
You will be able to manage and search for data.
6969

7070
## Getting started
@@ -101,9 +101,9 @@ This will start a RediSQL instance and allow you to work directly with RediSQL.
101101

102102
We create a few tutorial to guide you on using RediSQL with Node.js, Go(lang) and Python:
103103

104-
- [Using RediSQL with Python](http://redbeardlab.tech/rediSQL/blog/python/using-redisql-with-python/)
105-
- [Using RediSQL with Golang](http://redbeardlab.tech/rediSQL/blog/golang/using-redisql-with-golang/)
106-
- [Using RediSQL with Node.js](http://redbeardlab.tech/rediSQL/blog/node/using-redisql-with-node/)
104+
- [Using RediSQL with Python](http://redisql.redbeardlab.com/rediSQL/blog/python/using-redisql-with-python/)
105+
- [Using RediSQL with Golang](http://redisql.redbeardlab.com/rediSQL/blog/golang/using-redisql-with-golang/)
106+
- [Using RediSQL with Node.js](http://redisql.redbeardlab.com/rediSQL/blog/node/using-redisql-with-node/)
107107

108108
Please open an issue and request a tutorial for any other language you are intereted in.
109109

@@ -170,5 +170,5 @@ This software is licensed under the AGPL-v3, it is possible to purchase more per
170170
<RediSQL, SQL steroids for Redis.>
171171
Copyright (C) 2019 Simone Mosciatti
172172

173-
[api]: http://redbeardlab.tech/rediSQL/references/
173+
[api]: http://redisql.redbeardlab.com/rediSQL/references/
174174
[redis-download]: https://redis.io/download

redisql_lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "redisql_lib"
3-
version = "0.5.0"
3+
version = "0.5.1"
44
authors = ["Simone Mosciatti <[email protected]>"]
55

66
[build-dependencies]

redisql_lib/src/redis.rs

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ pub struct Loop {
245245
redis_context: ProtectedRedisContext,
246246
}
247247

248+
impl Drop for Loop {
249+
fn drop(&mut self) {
250+
debug!("### Dropping Loop ###")
251+
}
252+
}
253+
248254
unsafe impl Send for Loop {}
249255

250256
pub trait LoopData {
@@ -498,7 +504,6 @@ pub enum Command {
498504
client: BlockedClient,
499505
},
500506
MakeCopy {
501-
source: DBKey,
502507
destination: DBKey,
503508
client: BlockedClient,
504509
},
@@ -560,26 +565,26 @@ pub fn do_query(
560565

561566
/// implements the copy of the source database into the destination one
562567
/// it also leak the two DBKeys
563-
pub fn do_copy(
564-
source: DBKey,
565-
destination: DBKey,
568+
pub fn do_copy<L: LoopData>(
569+
source_db: &Arc<Mutex<sql::RawConnection>>,
570+
destination_loopdata: &L,
566571
) -> Result<QueryResult, err::RediSQLError> {
567-
let source_connection = source.loop_data.get_db();
568-
let destination_connection = destination.loop_data.get_db();
572+
debug!("DoCopy | Start");
569573

570574
let backup_result = {
571-
let source_db = source_connection.lock().unwrap();
572-
let destination_db = destination_connection.lock().unwrap();
575+
let destination_db = destination_loopdata.get_db();
576+
let destination_db = destination_db.lock().unwrap();
577+
let source_db = source_db.lock().unwrap();
573578
match make_backup(&source_db, &destination_db) {
574579
Err(e) => Err(RediSQLError::from(e)),
575580
Ok(_) => Ok(QueryResult::OK {}),
576581
}
577582
};
578583

579-
restore_previous_statements(&destination.loop_data);
580-
581-
std::mem::forget(source);
582-
std::mem::forget(destination);
584+
if backup_result.is_ok() {
585+
restore_previous_statements(destination_loopdata);
586+
}
587+
debug!("DoCopy | End");
583588

584589
backup_result
585590
}
@@ -973,20 +978,37 @@ pub fn listen_and_execute<'a, L: 'a + LoopData>(
973978
);
974979
}
975980
Ok(Command::MakeCopy {
976-
source,
977981
destination,
978982
client,
979983
}) => {
980-
// The DBKeys MUST be leaked, they are leaked by do_copy
981-
let result = do_copy(source, destination);
982-
return_value(&client, result);
984+
loopdata.with_contex_set(
985+
Context::thread_safe(&client),
986+
|_| {
987+
debug!("MakeCopy | Doing do_copy");
988+
let destination_loopdata =
989+
&destination.loop_data;
990+
let result = do_copy(
991+
&loopdata.get_db(),
992+
destination_loopdata,
993+
);
994+
match result {
995+
Ok(_) => STATISTICS.copy_ok(),
996+
Err(_) => STATISTICS.copy_err(),
997+
};
998+
return_value(&client, result);
999+
},
1000+
);
1001+
std::mem::forget(destination);
9831002
}
9841003
Ok(Command::Stop) => {
9851004
debug!("Stop, exiting from work loop");
9861005
return;
9871006
}
9881007
Err(RecvError) => {
989-
debug!("RecvError, exiting from work loop");
1008+
debug!(
1009+
"RecvError {}, exiting from work loop",
1010+
RecvError
1011+
);
9901012
return;
9911013
}
9921014
}

src/commands.rs

Lines changed: 75 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -894,81 +894,88 @@ pub extern "C" fn MakeCopy(
894894
STATISTICS.copy();
895895
let (context, argvector) = r::create_argument(ctx, argv, argc);
896896

897-
if argvector.len() != 3 {
898-
let error = CString::new(
899-
"Wrong number of arguments, it accepts exactly 3",
900-
)
901-
.unwrap();
902-
STATISTICS.copy_err();
903-
return unsafe {
904-
r::rm::ffi::RedisModule_ReplyWithError.unwrap()(
905-
context.as_ptr(),
906-
error.as_ptr(),
907-
)
908-
};
909-
}
910-
911-
let source_db =
912-
get_dbkey_from_name(context.as_ptr(), argvector[1]);
913-
if source_db.is_err() {
914-
let error =
915-
CString::new("Error in opening the SOURCE database")
916-
.unwrap();
917-
STATISTICS.copy_err();
918-
return unsafe {
919-
r::rm::ffi::RedisModule_ReplyWithError.unwrap()(
920-
context.as_ptr(),
921-
error.as_ptr(),
922-
)
923-
};
924-
}
925-
let source_db = source_db.unwrap();
897+
match argvector.len() {
898+
3 => with_ch_and_loopdata(
899+
context.as_ptr(),
900+
argvector[1],
901+
|ch_loopdata| match ch_loopdata {
902+
Err(key_type) => {
903+
STATISTICS.copy_err();
926904

927-
let dest_db = get_dbkey_from_name(context.as_ptr(), argvector[2]);
928-
if dest_db.is_err() {
929-
let error =
905+
reply_with_error_from_key_type(
906+
context.as_ptr(),
907+
key_type,
908+
)
909+
}
910+
Ok((ch, _loopdata)) => {
911+
let dest_db = get_dbkey_from_name(
912+
context.as_ptr(),
913+
argvector[2],
914+
);
915+
if dest_db.is_err() {
916+
let error =
930917
CString::new("Error in opening the DESTINATION database")
931918
.unwrap();
932-
STATISTICS.copy_err();
933-
return unsafe {
934-
r::rm::ffi::RedisModule_ReplyWithError.unwrap()(
935-
context.as_ptr(),
936-
error.as_ptr(),
937-
)
938-
};
939-
}
940-
let dest_db = dest_db.unwrap();
941-
942-
let blocked_client = r::rm::BlockedClient {
943-
client: unsafe {
944-
r::rm::ffi::RedisModule_BlockClient.unwrap()(
945-
context.as_ptr(),
946-
Some(reply_create_statement),
947-
Some(timeout),
948-
Some(free_privdata),
949-
10000,
950-
)
951-
},
952-
};
919+
STATISTICS.copy_err();
920+
return unsafe {
921+
r::rm::ffi::RedisModule_ReplyWithError
922+
.unwrap()(
923+
context.as_ptr(),
924+
error.as_ptr(),
925+
)
926+
};
927+
}
928+
let dest_db = dest_db.unwrap();
953929

954-
let ch = &source_db.tx.clone();
930+
let blocked_client = r::rm::BlockedClient {
931+
client: unsafe {
932+
r::rm::ffi::RedisModule_BlockClient
933+
.unwrap()(
934+
context.as_ptr(),
935+
Some(reply_create_statement),
936+
Some(timeout),
937+
Some(free_privdata),
938+
10000,
939+
)
940+
},
941+
};
955942

956-
let cmd = r::Command::MakeCopy {
957-
source: source_db,
958-
destination: dest_db,
959-
client: blocked_client,
960-
};
943+
let cmd = r::Command::MakeCopy {
944+
destination: dest_db,
945+
client: blocked_client,
946+
};
961947

962-
debug!("MakeCopy | End");
963-
match ch.send(cmd) {
964-
Ok(()) => {
965-
debug!("MakeCopy | Successfully send command");
966-
unsafe {
967-
Replicate(&context, "REDISQL.COPY.NOW", argv, argc);
968-
}
969-
r::rm::ffi::REDISMODULE_OK
948+
match ch.send(cmd) {
949+
Ok(()) => {
950+
debug!("MakeCopy | Successfully send command");
951+
unsafe {
952+
Replicate(
953+
&context,
954+
"REDISQL.COPY.NOW",
955+
argv,
956+
argc,
957+
);
958+
}
959+
r::rm::ffi::REDISMODULE_OK
960+
}
961+
Err(_) => r::rm::ffi::REDISMODULE_OK,
962+
}
963+
}
964+
},
965+
),
966+
_ => {
967+
let error = CString::new(
968+
"Wrong number of arguments, it accepts exactly 3",
969+
)
970+
.unwrap();
971+
STATISTICS.copy_err();
972+
return unsafe {
973+
r::rm::ffi::RedisModule_ReplyWithError.unwrap()(
974+
context.as_ptr(),
975+
error.as_ptr(),
976+
)
977+
};
970978
}
971-
Err(_) => r::rm::ffi::REDISMODULE_OK,
972979
}
973980
}
974981

0 commit comments

Comments
 (0)