Skip to content

Commit 81371ee

Browse files
committed
update
1 parent 32dffdc commit 81371ee

File tree

10 files changed

+493
-794
lines changed

10 files changed

+493
-794
lines changed

.github/workflows/build.yml

Lines changed: 292 additions & 286 deletions
Large diffs are not rendered by default.

Cargo.lock

Lines changed: 16 additions & 291 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,4 @@ panic = "abort" # Уменьшение объема кода для обрабо
2525
strip = true # Удаление символов отладки
2626

2727
[dev-dependencies]
28-
tokio = { version = "1.24.2", features = ["net", "macros"] }
29-
tokio-test = "0.4.2"
30-
fastcgi-client = "0.8.0"
31-
indoc = "2.0.0"
3228
rand = "0.8.5"

src/lib.rs

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -368,33 +368,52 @@ impl RocksDB {
368368
}
369369
}
370370

371-
pub fn compact_range(&self, start: Option<String>, end: Option<String>, cf_name: Option<String>) -> PhpResult<()> {
371+
pub fn compact_range(
372+
&self,
373+
start: Option<String>,
374+
end: Option<String>,
375+
cf_name: Option<String>,
376+
) -> PhpResult<()> {
372377
match cf_name {
373378
Some(cf_name) => {
374379
let cf = self
375380
.db
376381
.cf_handle(&cf_name)
377382
.ok_or("Column family not found")?;
378-
self.db
379-
.compact_range_cf(&cf, start.as_ref().map(|s| s.as_bytes()), end.as_ref().map(|s| s.as_bytes()));
383+
self.db.compact_range_cf(
384+
&cf,
385+
start.as_ref().map(|s| s.as_bytes()),
386+
end.as_ref().map(|s| s.as_bytes()),
387+
);
380388
}
381389
None => {
382-
self.db
383-
.compact_range(start.as_ref().map(|s| s.as_bytes()), end.as_ref().map(|s| s.as_bytes()));
390+
self.db.compact_range(
391+
start.as_ref().map(|s| s.as_bytes()),
392+
end.as_ref().map(|s| s.as_bytes()),
393+
);
384394
}
385395
}
386396
Ok(())
387397
}
388398

389-
390399
pub fn get_live_files(&self) -> PhpResult<Vec<String>> {
391-
let live_files = self.db.live_files().map_err(|e| PhpException::from(e.to_string()))?;
400+
let live_files = self
401+
.db
402+
.live_files()
403+
.map_err(|e| PhpException::from(e.to_string()))?;
392404
let live_file_names = live_files.iter().map(|lf| lf.name.clone()).collect();
393405
Ok(live_file_names)
394406
}
395407

396-
pub fn set_options(&self, options: HashMap<String, String>, cf_name: Option<String>) -> PhpResult<()> {
397-
let options_vec: Vec<(&str, &str)> = options.iter().map(|(k, v)| (k.as_str(), v.as_str())).collect();
408+
pub fn set_options(
409+
&self,
410+
options: HashMap<String, String>,
411+
cf_name: Option<String>,
412+
) -> PhpResult<()> {
413+
let options_vec: Vec<(&str, &str)> = options
414+
.iter()
415+
.map(|(k, v)| (k.as_str(), v.as_str()))
416+
.collect();
398417
match cf_name {
399418
Some(cf_name) => {
400419
let cf = self
@@ -410,7 +429,11 @@ impl RocksDB {
410429
Ok(())
411430
}
412431

413-
pub fn set_compression(&self, compression_type: String, cf_name: Option<String>) -> PhpResult<()> {
432+
pub fn set_compression(
433+
&self,
434+
compression_type: String,
435+
cf_name: Option<String>,
436+
) -> PhpResult<()> {
414437
let compression = match compression_type.as_str() {
415438
"none" => rust_rocksdb::DBCompressionType::None,
416439
"snappy" => rust_rocksdb::DBCompressionType::Snappy,
@@ -425,23 +448,37 @@ impl RocksDB {
425448
opts.set_compression_type(compression);
426449
match cf_name {
427450
Some(cf_name) => {
428-
let cf = self.db.cf_handle(&cf_name).ok_or("Column family not found")?;
429-
self.db.set_options_cf(cf, &[("compression", compression_type.as_str())])
451+
let cf = self
452+
.db
453+
.cf_handle(&cf_name)
454+
.ok_or("Column family not found")?;
455+
self.db
456+
.set_options_cf(cf, &[("compression", compression_type.as_str())])
430457
}
431-
None => self.db.set_options(&[("compression", compression_type.as_str())]),
432-
}.map_err(|e| e.to_string().into())
458+
None => self
459+
.db
460+
.set_options(&[("compression", compression_type.as_str())]),
461+
}
462+
.map_err(|e| e.to_string().into())
433463
}
434464

435465
pub fn set_write_buffer_size(&self, size: usize, cf_name: Option<String>) -> PhpResult<()> {
436466
let mut opts = Options::default();
437467
opts.set_write_buffer_size(size);
438468
match cf_name {
439469
Some(cf_name) => {
440-
let cf = self.db.cf_handle(&cf_name).ok_or("Column family not found")?;
441-
self.db.set_options_cf(cf, &[("write_buffer_size", size.to_string().as_str())])
470+
let cf = self
471+
.db
472+
.cf_handle(&cf_name)
473+
.ok_or("Column family not found")?;
474+
self.db
475+
.set_options_cf(cf, &[("write_buffer_size", size.to_string().as_str())])
442476
}
443-
None => self.db.set_options(&[("write_buffer_size", size.to_string().as_str())]),
444-
}.map_err(|e| e.to_string().into())
477+
None => self
478+
.db
479+
.set_options(&[("write_buffer_size", size.to_string().as_str())]),
480+
}
481+
.map_err(|e| e.to_string().into())
445482
}
446483

447484
pub fn set_cache_size(&self, size: usize, cf_name: Option<String>) -> PhpResult<()> {
@@ -451,11 +488,18 @@ impl RocksDB {
451488
opts.set_block_based_table_factory(&cache);
452489
match cf_name {
453490
Some(cf_name) => {
454-
let cf = self.db.cf_handle(&cf_name).ok_or("Column family not found")?;
455-
self.db.set_options_cf(cf, &[("block_cache", size.to_string().as_str())])
491+
let cf = self
492+
.db
493+
.cf_handle(&cf_name)
494+
.ok_or("Column family not found")?;
495+
self.db
496+
.set_options_cf(cf, &[("block_cache", size.to_string().as_str())])
456497
}
457-
None => self.db.set_options(&[("block_cache", size.to_string().as_str())]),
458-
}.map_err(|e| e.to_string().into())
498+
None => self
499+
.db
500+
.set_options(&[("block_cache", size.to_string().as_str())]),
501+
}
502+
.map_err(|e| e.to_string().into())
459503
}
460504
}
461505

tests/test_backup.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use indoc::indoc;
21
use std::thread::sleep;
32
use std::time;
43

@@ -13,7 +12,8 @@ fn setup() {
1312
#[test]
1413
fn test_backup() {
1514
setup();
16-
let output = php_request(indoc! { r#"
15+
let output = php_request(
16+
r#"
1717
<?php
1818
$dbPath = __DIR__ . "/temp/testdb_backup";
1919
$backupPath = __DIR__ . "/temp/backup1";
@@ -23,14 +23,16 @@ fn test_backup() {
2323
$info = $backup->info();
2424
var_dump($info);
2525
$backup = null; // Free the connection
26-
"#});
26+
"#,
27+
);
2728
assert!(output.contains("backup_id"));
2829
}
2930

3031
#[test]
3132
fn test_restore_backup() {
3233
setup();
33-
let output = php_request(indoc! { r#"
34+
let output = php_request(
35+
r#"
3436
<?php
3537
$dbPath = __DIR__ . "/temp/backup2";
3638
@@ -46,14 +48,12 @@ fn test_restore_backup() {
4648
$backup->restore(1, $restorePath);
4749
$db = new RocksDB($restorePath, 3600);
4850
$value = $db->get("key1");
49-
var_dump($value);
51+
echo $value;
5052
$backup = null; // Free the connection
5153
$db = null; // Free the connection
52-
"#});
53-
assert_eq!(
54-
indoc! {r#"
55-
string(6) "value1"
56-
"#},
57-
output
54+
"#,
5855
);
56+
57+
// Проверяем, что значение "value1" было восстановлено
58+
assert_eq!(output.trim(), "value1");
5959
}

tests/test_column_family.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use indoc::indoc;
21
use std::thread::sleep;
32
use std::time;
43

@@ -13,7 +12,8 @@ fn setup() {
1312
#[test]
1413
fn test_create_column_family() {
1514
setup();
16-
let output = php_request(indoc! { r#"
15+
let output = php_request(
16+
r#"
1717
<?php
1818
$dbPath = __DIR__ . "/temp/testdb_cf";
1919
$db = new RocksDB($dbPath, 3600); // 3600 seconds TTL
@@ -22,14 +22,16 @@ fn test_create_column_family() {
2222
var_dump($cfs);
2323
$db->dropColumnFamily("new_cf");
2424
$db = null; // Free the connection
25-
"#});
25+
"#,
26+
);
2627
assert!(output.contains("new_cf"));
2728
}
2829

2930
#[test]
3031
fn test_drop_column_family() {
3132
setup();
32-
let output = php_request(indoc! { r#"
33+
let output = php_request(
34+
r#"
3335
<?php
3436
$dbPath = __DIR__ . "/temp/testdb_drop_cf";
3537
$db = new RocksDB($dbPath, 3600); // 3600 seconds TTL
@@ -38,14 +40,16 @@ fn test_drop_column_family() {
3840
$cfs = $db->listColumnFamilies($dbPath);
3941
var_dump($cfs);
4042
$db = null; // Free the connection
41-
"#});
43+
"#,
44+
);
4245
assert!(!output.contains("new_cf_drop"));
4346
}
4447

4548
#[test]
4649
fn test_list_column_families() {
4750
setup();
48-
let output = php_request(indoc! { r#"
51+
let output = php_request(
52+
r#"
4953
<?php
5054
$dbPath = __DIR__ . "/temp/testdb_list_cf";
5155
$db = new RocksDB($dbPath, 3600); // 3600 seconds TTL
@@ -54,7 +58,8 @@ fn test_list_column_families() {
5458
$cfs = $db->listColumnFamilies($dbPath);
5559
var_dump($cfs);
5660
$db = null; // Free the connection
57-
"#});
61+
"#,
62+
);
5863
assert!(output.contains("cf1"));
5964
assert!(output.contains("cf2"));
6065
}

0 commit comments

Comments
 (0)