Skip to content

Commit

Permalink
ObjectBox Swift database 1.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
greenrobot-team committed Feb 14, 2024
1 parent 4d56731 commit 58905ab
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Expand Up @@ -16,8 +16,8 @@ let package = Package(
targets: [
.binaryTarget(
name: "ObjectBox",
url: "https://github.com/objectbox/objectbox-swift/releases/download/v1.9.1/ObjectBox-xcframework-1.9.1.zip",
checksum: "e79910ffaac143b84427fa58748a33ce4f5afbad5e6bb2e1f025a239c8fcafd2"
url: "https://github.com/objectbox/objectbox-swift/releases/download/v1.9.2/ObjectBox-xcframework-1.9.2.zip",
checksum: "e70e580fe40ef752fbb29b4cb0a3be1c51f3024020bf1832a73e79e921b42dd3"
)
]
)
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -118,6 +118,7 @@ Here's a list of ObjectBox releases, and the Swift versions they were compiled w

| ObjectBox version(s) | Swift version |
|:--------------------:|:-------------:|
| 1.9.2 | 5.9 |
| 1.9.1 | 5.9 |
| 1.9.0 | 5.8.1 |
| 1.8.1 | 5.7.2 |
Expand Down
4 changes: 2 additions & 2 deletions Source/fetch_dependencies.command
Expand Up @@ -99,8 +99,8 @@ if [ -d "$code_dir" ] && [ "$staging_repo" != "true" ]; then # Do we have an exi
popd
else # Download static public release and unzip into $dest
if [ ! -d "${dest_dir}" ] || [ ! -e "${dest_dir}/libObjectBoxCore-iOS.a" ]; then
version=1.9.1
c_version=0.19.0
version=1.9.2
c_version=0.21.0
archive_path="${my_dir}/external/objectbox-static.zip"
if [ "$staging_repo" == "true" ]; then
release_url_path="https://github.com/objectbox/objectbox-swift-spec-staging/releases/download/v1.x"
Expand Down
268 changes: 267 additions & 1 deletion Source/ios-framework/CommonSource/Internal/objectbox-c-sync.h
Expand Up @@ -34,7 +34,7 @@
#include "objectbox-c.h"

#if defined(static_assert) || defined(__cplusplus)
static_assert(OBX_VERSION_MAJOR == 0 && OBX_VERSION_MINOR == 19 && OBX_VERSION_PATCH == 0, // NOLINT
static_assert(OBX_VERSION_MAJOR == 0 && OBX_VERSION_MINOR == 21 && OBX_VERSION_PATCH == 0, // NOLINT
"Versions of objectbox.h and objectbox-sync.h files do not match, please update");
#endif

Expand All @@ -51,10 +51,16 @@ extern "C" {
struct OBX_sync;
typedef struct OBX_sync OBX_sync;

/// Specifies user-side credential types as well as server-side authenticator types.
/// Some credentail types do not make sense as authenticators such as OBXSyncCredentialsType_USER_PASSWORD which
/// specifies a generic client-side credential type.
typedef enum {
OBXSyncCredentialsType_NONE = 1,
OBXSyncCredentialsType_SHARED_SECRET = 2,
OBXSyncCredentialsType_GOOGLE_AUTH = 3,
OBXSyncCredentialsType_SHARED_SECRET_SIPPED = 4,
OBXSyncCredentialsType_OBX_ADMIN_USER = 5,
OBXSyncCredentialsType_USER_PASSWORD = 6,
} OBXSyncCredentialsType;

// TODO sync prefix
Expand Down Expand Up @@ -91,6 +97,13 @@ typedef enum {
OBXSyncCode_TX_VIOLATED_UNIQUE = 71,
} OBXSyncCode;

/// Sync-level error reporting codes, passed via obx_sync_listener_error().
typedef enum {
/// Sync client received rejection of transaction writes due to missing permissions.
/// Until reconnecting with new credentials client will run in receive-only mode.
OBXSyncError_REJECT_TX_NO_PERMISSION = 1
} OBXSyncError;

typedef enum {
OBXSyncObjectType_FlatBuffers = 1,
OBXSyncObjectType_String = 2,
Expand Down Expand Up @@ -150,6 +163,11 @@ typedef void OBX_sync_listener_login_failure(void* arg, OBXSyncCode code);
/// @param arg is a pass-through argument passed to the called API
typedef void OBX_sync_listener_complete(void* arg);

/// Callend when sync-level errors occur
/// @param arg is a pass-through argument passed to the called API
/// @param error error code indicating sync-level error events
typedef void OBX_sync_listener_error(void* arg, OBXSyncError error);

/// Called with fine grained sync changes (IDs of put and removed entities)
/// @param arg is a pass-through argument passed to the called API
typedef void OBX_sync_listener_change(void* arg, const OBX_sync_change_array* changes);
Expand All @@ -168,6 +186,10 @@ typedef void OBX_sync_listener_msg_objects(void* arg, const OBX_sync_msg_objects
/// To configure this differently, call obx_sync_request_updates_mode() with the wanted mode.
OBX_C_API OBX_sync* obx_sync(OBX_store* store, const char* server_url);

/// Creates a sync client associated with the given store and a list of sync server URL.
/// For details, see obx_sync()
OBX_C_API OBX_sync* obx_sync_urls(OBX_store* store, const char* server_urls[], size_t server_urls_count);

/// Stops and closes (deletes) the sync client, freeing its resources.
OBX_C_API obx_err obx_sync_close(OBX_sync* sync);

Expand All @@ -177,6 +199,14 @@ OBX_C_API obx_err obx_sync_close(OBX_sync* sync);
/// @param data may be NULL in combination with OBXSyncCredentialsType_NONE
OBX_C_API obx_err obx_sync_credentials(OBX_sync* sync, OBXSyncCredentialsType type, const void* data, size_t size);

/// Set username/password credentials to authenticate the client with the server.
/// This is suitable for OBXSyncCredentialsType_OBX_ADMIN_USER and OBXSyncCredentialsType_USER_PASSWORD credential
/// types. Use obx_sync_credentials() for other credential types.
/// @param type should be OBXSyncCredentialsType_OBX_ADMIN_USER or OBXSyncCredentialsType_USER_PASSWORD
/// @returns OBX_ERROR_ILLEGAL_ARGUMENT if credential type does not support username/password authentication.
OBX_C_API obx_err obx_sync_credentials_user_password(OBX_sync* sync, OBXSyncCredentialsType type, const char* username,
const char* password);

/// Configures the maximum number of outgoing TX messages that can be sent without an ACK from the server.
/// @returns OBX_ERROR_ILLEGAL_ARGUMENT if value is not in the range 1-20
OBX_C_API obx_err obx_sync_max_messages_in_flight(OBX_sync* sync, int value);
Expand Down Expand Up @@ -343,6 +373,50 @@ OBX_C_API void obx_sync_listener_server_time(OBX_sync* sync, OBX_sync_listener_s
OBX_C_API void obx_sync_listener_msg_objects(OBX_sync* sync, OBX_sync_listener_msg_objects* listener,
void* listener_arg);

/// Set or overwrite a previously set 'error' listener - provides information about occurred sync-level errors.
/// @param listener set NULL to reset
/// @param listener_arg is a pass-through argument passed to the listener
OBX_C_API void obx_sync_listener_error(OBX_sync* sync, OBX_sync_listener_error* error, void* listener_arg);

//----------------------------------------------
// Sync Stats
//----------------------------------------------

/// Stats counter type IDs as passed to obx_sync_stats_u64().
typedef enum {
/// Total number of connects (u64)
OBXSyncStats_connects = 1,

/// Total number of succesful logins (u64)
OBXSyncStats_logins = 2,

/// Total number of messages received (u64)
OBXSyncStats_messagesReceived = 3,

/// Total number of messages sent (u64)
OBXSyncStats_messagesSent = 4,

/// Total number of errors during message sending (u64)
OBXSyncStats_messageSendFailures = 5,

/// Total number of bytes received via messages.
/// Note: this is measured on the application level and thus may not match e.g. the network level. (u64)
OBXSyncStats_messageBytesReceived = 6,

/// Total number of bytes sent via messages.
/// Note: this is measured on the application level and thus may not match e.g. the network level.
/// E.g. messages may be still enqueued so at least the timing will differ. (u64)
OBXSyncStats_messageBytesSent = 7,

} OBXSyncStats;

/// Get u64 value for sync statistics.
/// @param counter_type the counter value to be read.
/// @param out_count receives the counter value.
/// @return OBX_SUCCESS if the counter has been successfully retrieved.
/// @return OBX_ERROR_ILLEGAL_ARGUMENT if counter_type is undefined.
OBX_C_API obx_err obx_sync_stats_u64(OBX_sync* sync, OBXSyncStats counter_type, uint64_t* out_count);

struct OBX_sync_server;
typedef struct OBX_sync_server OBX_sync_server;

Expand Down Expand Up @@ -385,6 +459,12 @@ OBX_C_API obx_err obx_sync_server_certificate_path(OBX_sync_server* server, cons
OBX_C_API obx_err obx_sync_server_credentials(OBX_sync_server* server, OBXSyncCredentialsType type, const void* data,
size_t size);

/// Enables authenticator for server. Can be called multiple times. Use before obx_sync_server_start().
/// Use obx_sync_server_credentials() for authenticators which requires additional credentials data (i.e. Google Auth
/// and shared secrets authenticators).
/// @param type should be one of the available authentications, it should not be OBXSyncCredentialsType_USER_PASSWORD.
OBX_C_API obx_err obx_sync_server_enable_auth(OBX_sync_server* server, OBXSyncCredentialsType type);

/// Sets the number of worker threads. Use before obx_sync_server_start().
/// @param thread_count The default is "0" which is hardware dependent, e.g. a multiple of CPU "cores".
OBX_C_API obx_err obx_sync_server_worker_threads(OBX_sync_server* server, int thread_count);
Expand Down Expand Up @@ -432,6 +512,192 @@ OBX_C_API uint16_t obx_sync_server_port(OBX_sync_server* server);
/// Returns the number of clients connected to this server.
OBX_C_API uint64_t obx_sync_server_connections(OBX_sync_server* server);

//----------------------------------------------
// Sync Server Stats
//----------------------------------------------

/// Stats counter type IDs as passed to obx_sync_server_stats_u64() (for u64 values) and obx_sync_server_stats_f64()
/// (for double (f64) values).
typedef enum {
/// Total number of client connections established (u64)
OBXSyncServerStats_connects = 1,

/// Total number of messages received from clients (u64)
OBXSyncServerStats_messagesReceived = 2,

/// Total number of messages sent to clients (u64)
OBXSyncServerStats_messagesSent = 3,

/// Total number of bytes received from clients via messages. (u64)
/// Note: this is measured on the application level and thus may not match e.g. the network level.
OBXSyncServerStats_messageBytesReceived = 4,

/// Total number of bytes sent to clients via messages. (u64)
/// Note: this is measured on the application level and thus may not match e.g. the network level.
/// E.g. messages may be still enqueued so at least the timing will differ.
OBXSyncServerStats_messageBytesSent = 5,

/// Full syncs performed (u64)
OBXSyncServerStats_fullSyncs = 6,

/// Processing was aborted due to clients disconnected (u64)
OBXSyncServerStats_disconnectAborts = 7,

/// Total number of client transactions applied (u64)
OBXSyncServerStats_clientTxsApplied = 8,

/// Total size in bytes of client transactions applied (u64)
OBXSyncServerStats_clientTxBytesApplied = 9,

/// Total size in number of operations of transactions applied (u64)
OBXSyncServerStats_clientTxOpsApplied = 10,

/// Total number of local (server initiated) transactions applied (u64)
OBXSyncServerStats_localTxsApplied = 11,

/// AsyncQ committed TXs (u64)
OBXSyncServerStats_asyncDbCommits = 12,

/// Total number of skipped transactions duplicates (have been already applied before) (u64)
OBXSyncServerStats_skippedTxDups = 13,

/// Total number of login successes (u64)
OBXSyncServerStats_loginSuccesses = 14,

/// Total number of login failures (u64)
OBXSyncServerStats_loginFailures = 15,

/// Total number of login failures due to bad user credentials (u64)
OBXSyncServerStats_loginFailuresUserBadCredentials = 16,

/// Total number of login failures due to authenticator not available (u64)
OBXSyncServerStats_loginFailuresAuthUnavailable = 17,

/// Total number of login failures due to user has no permissions (u64)
OBXSyncServerStats_loginFailuresUserNoPermission = 18,

/// Total number of errors during message sending (u64)
OBXSyncServerStats_messageSendFailures = 19,

/// Total number of protocol errors; e.g. offending clients (u64)
OBXSyncServerStats_errorsProtocol = 20,

/// Total number of errors in message handlers (u64)
OBXSyncServerStats_errorsInHandlers = 21,

/// Total number of times a client has been disconnected due to heart failure (u64)
OBXSyncServerStats_heartbeatFailures = 22,

/// Total number of received client heartbeats (u64)
OBXSyncServerStats_heartbeatsReceived = 23,

/// Total APPLY_TX messages HistoryPusher has sent out (u64)
OBXSyncServerStats_historicUpdateTxsSent = 24,

/// Total APPLY_TX messages newDataPusher has sent out (u64)
OBXSyncServerStats_newUpdateTxsSent = 25,

/// Total number of messages received from clients (u64)
OBXSyncServerStats_forwardedMessagesReceived = 26,

/// Total number of messages sent to clients (u64)
OBXSyncServerStats_forwardedMessagesSent = 27,

/// Total number of global-to-local cache hits (u64)
OBXSyncServerStats_cacheGlobalToLocalHits = 28,

/// Total number of global-to-local cache misses (u64)
OBXSyncServerStats_cacheGlobalToLocalMisses = 29,

/// Internal dev stat for ID Map caching (u64)
OBXSyncServerStats_cacheGlobalToLocalSize = 30,

/// Internal dev stat for ID Map caching (u64)
OBXSyncServerStats_cachePeerToLocalHits = 31,

/// Internal dev stat for ID Map caching (u64)
OBXSyncServerStats_cachePeerToLocalMisses = 32,

/// Internal dev stat for ID Map caching (u64)
OBXSyncServerStats_cacheLocalToPeerHits = 33,

/// Internal dev stat for ID Map caching (u64)
OBXSyncServerStats_cacheLocalToPeerMisses = 34,

/// Internal dev stat for ID Map caching (u64)
OBXSyncServerStats_cachePeerSize = 35,

/// Current cluster peer state (0 = unknown, 1 = leader, 2 = follower, 3 = candidate) (u64)
OBXSyncServerStats_clusterPeerState = 36,

/// Number of transactions between the current Tx and the oldest Tx currently ACKed on any client (current)
/// (f64)
OBXSyncServerStats_clientTxsBehind = 37,

/// Number of transactions between the current Tx and the oldest Tx currently ACKed on any client (minimum)
/// (u64)
OBXSyncServerStats_clientTxsBehind_min = 38,

/// Number of transactions between the current Tx and the oldest Tx currently ACKed on any client (maximum)
/// (u64)
OBXSyncServerStats_clientTxsBehind_max = 39,

/// Number of connected clients (current) (f64)
OBXSyncServerStats_connectedClients = 40,

/// Number of connected clients (minimum) (u64)
OBXSyncServerStats_connectedClients_min = 41,

/// Number of connected clients (maximum) (u64)
OBXSyncServerStats_connectedClients_max = 42,

/// Length of the queue for regular Tasks (current) (f64)
OBXSyncServerStats_queueLength = 43,

/// Length of the queue for regular Tasks (minimum) (u64)
OBXSyncServerStats_queueLength_min = 44,

/// Length of the queue for regular Tasks (maximum) (u64)
OBXSyncServerStats_queueLength_max = 45,

/// Length of the async queue (current) (f64)
OBXSyncServerStats_queueLengthAsync = 46,

/// Length of the async queue (minimum) (u64)
OBXSyncServerStats_queueLengthAsync_min = 47,

/// Length of the async queue (maximum) (u64)
OBXSyncServerStats_queueLengthAsync_max = 48,

/// Sequence number of TX log history (current) (f64)
OBXSyncServerStats_txHistorySequence = 49,

/// Sequence number of TX log history (minimum) (u64)
OBXSyncServerStats_txHistorySequence_min = 50,

/// Sequence number of TX log history (maximum) (u64)
OBXSyncServerStats_txHistorySequence_max = 51,

} OBXSyncServerStats;

/// Get u64 value for sync server statistics.
/// @param counter_type the counter value to be read (make sure to choose a uint64_t (u64) metric value type).
/// @param out_count receives the counter value.
/// @return OBX_SUCCESS if the counter has been successfully retrieved.
/// @return OBX_ERROR_ILLEGAL_ARGUMENT if counter_type is undefined (this also happens if the wrong type is requested)
/// @return OBX_ERROR_ILLEGAL_STATE if the server is not started.
OBX_C_API obx_err obx_sync_server_stats_u64(OBX_sync_server* server, OBXSyncServerStats counter_type,
uint64_t* out_value);

/// Get double value for sync server statistics.
/// @param counter_type the counter value to be read (make sure to use a double (f64) metric value type).
/// @param out_count receives the counter value.
/// @return OBX_SUCCESS if the counter has been successfully retrieved.
/// @return OBX_ERROR_ILLEGAL_ARGUMENT if counter_type is undefined (this also happens if the wrong type is requested)
/// @return OBX_ERROR_ILLEGAL_STATE if the server is not started.
OBX_C_API obx_err obx_sync_server_stats_f64(OBX_sync_server* server, OBXSyncServerStats counter_type,
double* out_value);

/// Get server runtime statistics.
/// The returned char* is valid until another call to obx_sync_server_stats_string() or the server is closed.
OBX_C_API const char* obx_sync_server_stats_string(OBX_sync_server* server, bool include_zero_values);
Expand Down
7 changes: 5 additions & 2 deletions Source/ios-framework/CommonSource/Internal/objectbox-c.h
Expand Up @@ -52,7 +52,7 @@ extern "C" {
/// When using ObjectBox as a dynamic library, you should verify that a compatible version was linked using
/// obx_version() or obx_version_is_at_least().
#define OBX_VERSION_MAJOR 0
#define OBX_VERSION_MINOR 19
#define OBX_VERSION_MINOR 21
#define OBX_VERSION_PATCH 0 // values >= 100 are reserved for dev releases leading to the next minor/major increase

//----------------------------------------------
Expand Down Expand Up @@ -147,6 +147,9 @@ typedef enum {
/// The default database "provider"; writes data persistently to disk (ACID).
OBXFeature_Lmdb = 13,

/// Vector search functionality; enables indexing for nearest neighbor search.
OBXFeature_VectorSearch = 14,

} OBXFeature;

/// Checks whether the given feature is available in the currently loaded library.
Expand Down Expand Up @@ -2417,7 +2420,7 @@ OBX_C_API obx_err obx_admin_opt_store_path(OBX_admin_options* opt, const char* d

/// Set the address and port on which the underlying http-server should server the admin web UI.
/// Defaults to "http://127.0.0.1:8081"
/// @note: you can use for e.g. "http://127.0.0.1:0" for automatic free port assignment - see obx_admin_bound_port().
/// @note: you can use for e.g. "http://127.0.0.1:0" for automatic free port assignment - see obx_admin_port().
OBX_C_API obx_err obx_admin_opt_bind(OBX_admin_options* opt, const char* uri);

/// Configure the server to use SSL, with the given certificate.
Expand Down

0 comments on commit 58905ab

Please sign in to comment.