Skip to content

Commit 696afc7

Browse files
committed
Rustfmt and C impl cleanup
1 parent 13c2623 commit 696afc7

File tree

18 files changed

+101
-316
lines changed

18 files changed

+101
-316
lines changed

.factory/automation.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ build:
268268
tool/test/stop-cluster-servers.sh
269269
exit $TEST_SUCCESS
270270
271-
272271
test-http-ts-behaviour-community:
273272
image: typedb-ubuntu-22.04
274273
type: foreground
@@ -287,6 +286,8 @@ build:
287286
tool/test/stop-community-server.sh
288287
exit $TEST_SUCCESS
289288
289+
# TODO: Run HTTP TS tests against clustered servers
290+
290291
# test-nodejs-integration:
291292
# image: typedb-ubuntu-22.04
292293
# dependencies:
@@ -533,7 +534,7 @@ build:
533534
release:
534535
filter:
535536
owner: typedb
536-
branch: [master]
537+
branch: [master, cluster-support-feature-branch]
537538
validation:
538539
validate-dependencies:
539540
image: typedb-ubuntu-22.04

c/src/analyze.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,33 @@
1717
* under the License.
1818
*/
1919

20-
use std::{
21-
ffi::c_char,
22-
ptr::{addr_of_mut, null_mut},
23-
};
20+
use std::{ffi::c_char, ptr::addr_of_mut};
2421

2522
use typedb_driver::{
2623
analyze::{
2724
conjunction::{
28-
Comparator, Conjunction, ConjunctionID, Constraint, ConstraintExactness, ConstraintSpan, ConstraintVertex,
29-
ConstraintWithSpan, NamedRole, Variable,
25+
Comparator, Conjunction, ConjunctionID, Constraint, ConstraintExactness, ConstraintVertex,
26+
ConstraintWithSpan, Variable, NamedRole
3027
},
3128
pipeline::{Pipeline, PipelineStage, ReduceAssignment, Reducer, SortOrder, SortVariable},
3229
AnalyzedQuery, Fetch, Function, ReturnOperation, TypeAnnotations, VariableAnnotations,
3330
},
3431
box_stream,
35-
concept::{type_::Type, AttributeType, Concept, Kind, ValueType},
32+
concept::{type_::Type, Concept, Kind},
3633
BoxPromise, Promise,
3734
};
3835

3936
use crate::{
40-
common::StringIterator,
41-
concept::ConceptIterator,
42-
error::try_release,
43-
iterator::{iterator_next, CIterator},
44-
memory::{
45-
borrow, free, release, release_optional, release_optional_string, release_string, string_view, take_ownership,
37+
common::{
38+
error::try_release,
39+
iterator::{iterator_next, CIterator},
40+
memory::{
41+
borrow, free, release, release_optional, release_optional_string, release_string, string_view,
42+
take_ownership,
43+
},
44+
StringIterator,
4645
},
46+
concept::ConceptIterator,
4747
};
4848

4949
// Iterators, promises & enums
@@ -406,15 +406,15 @@ pub extern "C" fn pipeline_stage_require_get_variables(stage: *const PipelineSta
406406
#[no_mangle]
407407
pub extern "C" fn pipeline_stage_offset_get_offset(stage: *const PipelineStage) -> i64 {
408408
let PipelineStage::Offset { offset, .. } = borrow(stage) else { unreachable!("Expected Offset stage") };
409-
(*offset as i64)
409+
*offset as i64
410410
}
411411

412412
/// Unwraps the <code>PipelineStage</code> instance as a Limit stage, and returns the limit applied.
413413
/// Will panic if the stage is not a Limit stage.
414414
#[no_mangle]
415415
pub extern "C" fn pipeline_stage_limit_get_limit(stage: *const PipelineStage) -> i64 {
416416
let PipelineStage::Limit { limit, .. } = borrow(stage) else { unreachable!("Expected Limit stage") };
417-
(*limit as i64)
417+
*limit as i64
418418
}
419419

420420
/// Unwraps the <code>PipelineStage</code> instance as a Sort stage, and returns the <code>SortVariable</code>.

c/src/database.rs

Lines changed: 0 additions & 144 deletions
This file was deleted.

c/src/database/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
* under the License.
1818
*/
1919

20-
pub(crate) mod database;
21-
pub(crate) mod database_manager;
20+
mod database;
21+
mod database_manager;

c/src/driver.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ use typedb_driver::{box_stream, Addresses, Credentials, DriverOptions, ServerRep
2323

2424
use crate::{
2525
common::{
26-
error::{try_release, unwrap_or_default, unwrap_void},
26+
error::{try_release, try_release_optional, unwrap_or_default, unwrap_void},
2727
iterator::CIterator,
2828
iterators_to_map,
29-
memory::{borrow, free, release, release_optional, string_array_view, string_view},
29+
memory::{borrow, free, release, string_array_view, string_view},
3030
},
3131
server::{
3232
consistency_level::{native_consistency_level, ConsistencyLevel},
@@ -215,7 +215,10 @@ pub extern "C" fn driver_replicas(driver: *const TypeDBDriver) -> *mut ServerRep
215215
/// Retrieves the server's primary replica, if exists.
216216
#[no_mangle]
217217
pub extern "C" fn driver_primary_replica(driver: *const TypeDBDriver) -> *mut ServerReplica {
218-
release_optional(borrow(driver).primary_replica())
218+
// TODO: Return somehow else!!
219+
try_release_optional(
220+
borrow(driver).primary_replica().map(|res| res.map(|rep| ServerReplica::Available(rep))).transpose(),
221+
)
219222
}
220223

221224
/// Registers a new replica in the cluster the driver is currently connected to. The registered

c/src/server/server_replica.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
use std::{ffi::c_char, ptr::addr_of_mut};
2121

22-
use typedb_driver::{ReplicaRole, ServerReplica};
22+
use typedb_driver::{Replica, ReplicaRole, ServerReplica};
2323

2424
use crate::common::{
2525
iterator::{iterator_next, CIterator},
26-
memory::{borrow, free, release_string},
26+
memory::{borrow, free, release_optional_string},
2727
};
2828

2929
/// Iterator over the <code>ServerReplica</code> corresponding to each replica of a TypeDB cluster.
@@ -57,13 +57,19 @@ pub extern "C" fn server_replica_get_id(replica_info: *const ServerReplica) -> i
5757
/// Returns the address this replica is hosted at.
5858
#[no_mangle]
5959
pub extern "C" fn server_replica_get_address(replica_info: *const ServerReplica) -> *mut c_char {
60-
release_string(borrow(replica_info).address().to_string())
60+
release_optional_string(borrow(replica_info).address().map(|address| address.to_string()))
6161
}
6262

63-
/// Returns whether this is the primary replica of the raft cluster or any of the supporting types.
63+
/// Returns whether the role of this replica is set.
6464
#[no_mangle]
65-
pub extern "C" fn server_replica_get_type(replica_info: *const ServerReplica) -> ReplicaRole {
66-
borrow(replica_info).role().unwrap() // TODO: Return optional!
65+
pub extern "C" fn server_replica_has_type(replica_info: *const ServerReplica) -> bool {
66+
borrow(replica_info).role().is_some()
67+
}
68+
69+
/// Returns whether this is the primary replica of the raft cluster or any of the supporting roles.
70+
#[no_mangle]
71+
pub extern "C" fn server_replica_get_role(replica_info: *const ServerReplica) -> ReplicaRole {
72+
borrow(replica_info).role().unwrap()
6773
}
6874

6975
/// Checks whether this is the primary replica of the raft cluster.
@@ -72,8 +78,14 @@ pub extern "C" fn server_replica_is_primary(replica_info: *const ServerReplica)
7278
borrow(replica_info).is_primary()
7379
}
7480

81+
/// Returns whether the raft protocol ‘term’ of this replica exists.
82+
#[no_mangle]
83+
pub extern "C" fn server_replica_has_term(replica_info: *const ServerReplica) -> bool {
84+
borrow(replica_info).term().is_some()
85+
}
86+
7587
/// Returns the raft protocol ‘term’ of this replica.
7688
#[no_mangle]
7789
pub extern "C" fn server_replica_get_term(replica_info: *const ServerReplica) -> i64 {
78-
borrow(replica_info).term().unwrap() as i64 // TODO: Return optional!
90+
borrow(replica_info).term().unwrap() as i64
7991
}

c/src/user/user.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@ use std::ffi::c_char;
2121

2222
use typedb_driver::User;
2323

24-
use crate::{
25-
common::{
26-
error::unwrap_void,
27-
memory::{borrow, free, release_string, string_view, take_ownership},
28-
},
29-
memory::take_ownership,
24+
use crate::common::{
25+
error::unwrap_void,
26+
memory::{borrow, free, release_string, string_view, take_ownership},
3027
};
3128

3229
/// Frees the native rust <code>User</code> object.

c/swig/typedb_driver_java.swg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@
132132
%nojavaexception server_replica_get_address;
133133
%nojavaexception server_replica_is_primary;
134134
%nojavaexception server_replica_get_id;
135-
%nojavaexception server_replica_get_type;
135+
%nojavaexception server_replica_get_role;
136+
%nojavaexception server_replica_has_role;
136137
%nojavaexception server_replica_get_term;
138+
%nojavaexception server_replica_has_term;
137139

138140
%nojavaexception database_get_name;
139141

java/api/server/ServerReplica.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package com.typedb.driver.api.server;
2121

2222
import javax.annotation.CheckReturnValue;
23+
import java.util.Optional;
2324

2425
/**
2526
* The metadata and state of an individual raft replica of a driver connection.
@@ -43,7 +44,7 @@ public interface ServerReplica {
4344
* Returns whether this is the primary replica of the raft cluster or any of the supporting types.
4445
*/
4546
@CheckReturnValue
46-
ReplicaType getType();
47+
Optional<ReplicaType> getRole();
4748

4849
/**
4950
* Checks whether this is the primary replica of the raft cluster.
@@ -55,5 +56,5 @@ public interface ServerReplica {
5556
* Returns the raft protocol ‘term’ of this replica.
5657
*/
5758
@CheckReturnValue
58-
long getTerm();
59+
Optional<Long> getTerm();
5960
}

0 commit comments

Comments
 (0)