v2.1.22 - Added --start-caching and --reset-backfill CLI options, redirected caching_relay output to log file, increased backfill page size to 200 and max cap to 1000 for better completeness
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
|
||||
/* Maximum limit we will bump a saturated page to before marking an author
|
||||
* blocked at a timestamp. Keeps a single query bounded. */
|
||||
#define CR_BACKFILL_MAX_PAGE_CAP 200
|
||||
#define CR_BACKFILL_MAX_PAGE_CAP 1000
|
||||
|
||||
typedef struct {
|
||||
int window_index;
|
||||
|
||||
@@ -13,6 +13,8 @@ ADMIN_KEY=""
|
||||
RELAY_KEY=""
|
||||
PORT_OVERRIDE=""
|
||||
DEBUG_LEVEL="5"
|
||||
START_CACHING=false
|
||||
RESET_BACKFILL=false
|
||||
DB_BACKEND="postgres"
|
||||
DB_CONNSTRING=""
|
||||
DB_HOST=""
|
||||
@@ -75,6 +77,14 @@ while [[ $# -gt 0 ]]; do
|
||||
PRESERVE_DATABASE=true
|
||||
shift
|
||||
;;
|
||||
--start-caching)
|
||||
START_CACHING=true
|
||||
shift
|
||||
;;
|
||||
--reset-backfill)
|
||||
RESET_BACKFILL=true
|
||||
shift
|
||||
;;
|
||||
--test-keys|-t)
|
||||
USE_TEST_KEYS=true
|
||||
# Read keys from .test_keys file
|
||||
@@ -359,6 +369,8 @@ if [ "$HELP" = true ]; then
|
||||
echo " --db-name <name> PostgreSQL database name"
|
||||
echo " --db-user <user> PostgreSQL database user"
|
||||
echo " --db-password <pass> PostgreSQL database password"
|
||||
echo " --start-caching Auto-start the caching service on startup"
|
||||
echo " --reset-backfill Clear caching backfill progress (use with --start-caching)"
|
||||
echo " --help, -h Show this help message"
|
||||
echo ""
|
||||
echo "Event-Based Configuration:"
|
||||
@@ -579,6 +591,16 @@ if [ -n "$DB_PASSWORD" ]; then
|
||||
RELAY_ARGS="$RELAY_ARGS --db-password '$DB_PASSWORD'"
|
||||
fi
|
||||
|
||||
if [ "$START_CACHING" = true ]; then
|
||||
RELAY_ARGS="$RELAY_ARGS --start-caching"
|
||||
echo "Auto-starting caching service on startup"
|
||||
fi
|
||||
|
||||
if [ "$RESET_BACKFILL" = true ]; then
|
||||
RELAY_ARGS="$RELAY_ARGS --reset-backfill"
|
||||
echo "Resetting caching backfill progress before start"
|
||||
fi
|
||||
|
||||
# Change to build directory before starting relay so database files are created there
|
||||
cd build
|
||||
# Start relay in background and capture its PID
|
||||
|
||||
@@ -75,14 +75,21 @@ static int caching_service_start_fork(const char* binary_path, const char* pg_co
|
||||
close(devnull);
|
||||
}
|
||||
|
||||
// Redirect stdout/stderr to a log file or /dev/null
|
||||
// For now, send to /dev/null. A future improvement could
|
||||
// redirect to a configurable log file.
|
||||
devnull = open("/dev/null", O_WRONLY);
|
||||
if (devnull >= 0) {
|
||||
dup2(devnull, STDOUT_FILENO);
|
||||
dup2(devnull, STDERR_FILENO);
|
||||
close(devnull);
|
||||
// Redirect stdout/stderr to a log file for debugging.
|
||||
// The log file is created in the relay's working directory (build/).
|
||||
int logfile = open("caching_relay.log", O_WRONLY | O_CREAT | O_APPEND, 0644);
|
||||
if (logfile >= 0) {
|
||||
dup2(logfile, STDOUT_FILENO);
|
||||
dup2(logfile, STDERR_FILENO);
|
||||
close(logfile);
|
||||
} else {
|
||||
// Fallback to /dev/null if log file can't be opened
|
||||
devnull = open("/dev/null", O_WRONLY);
|
||||
if (devnull >= 0) {
|
||||
dup2(devnull, STDOUT_FILENO);
|
||||
dup2(devnull, STDERR_FILENO);
|
||||
close(devnull);
|
||||
}
|
||||
}
|
||||
|
||||
// Build argv for the caching_relay binary.
|
||||
|
||||
@@ -36,6 +36,8 @@ typedef struct {
|
||||
char relay_privkey_override[65]; // Empty string = not set, 64-char hex = override
|
||||
int strict_port; // 0 = allow port increment, 1 = fail if exact port unavailable
|
||||
int debug_level; // 0-5, default 0 (no debug output)
|
||||
int start_caching; // 0 = don't auto-start, 1 = start caching service on startup
|
||||
int reset_backfill; // 0 = no, 1 = clear caching_backfill_progress before starting
|
||||
char db_connstring_override[1024];
|
||||
char db_host[128];
|
||||
int db_port; // 0 = not set
|
||||
|
||||
@@ -148,7 +148,7 @@ static const struct {
|
||||
{"caching_live_resubscribe_seconds", "300"}, // Live subscription resubscribe interval
|
||||
{"caching_backfill_enabled", "true"}, // Enable historical backfill
|
||||
{"caching_backfill_windows", "86400,604800,2592000,7776000,31536000"}, // Backfill window schedule in seconds
|
||||
{"caching_backfill_page_size", "50"}, // Initial backfill query page size
|
||||
{"caching_backfill_page_size", "200"}, // Initial backfill query page size
|
||||
{"caching_backfill_tick_interval_ms", "5000"}, // Minimum delay between backfill queries
|
||||
{"caching_backfill_window_cooldown_seconds", "60"}, // Delay between completed windows
|
||||
{"caching_follow_graph_refresh_seconds", "600"}, // Kind-3 follow graph refresh interval
|
||||
|
||||
+35
-1
@@ -2299,6 +2299,8 @@ void print_usage(const char* program_name) {
|
||||
printf(" --db-name NAME PostgreSQL database name (default: crelay)\n");
|
||||
printf(" --db-user USER PostgreSQL user (default: crelay)\n");
|
||||
printf(" --db-password PASS PostgreSQL password\n");
|
||||
printf(" --start-caching Auto-start the caching service on startup\n");
|
||||
printf(" --reset-backfill Clear caching_backfill_progress before starting (use with --start-caching)\n");
|
||||
printf("\n");
|
||||
printf("Configuration:\n");
|
||||
printf(" This relay uses event-based configuration stored in the database.\n");
|
||||
@@ -2338,7 +2340,9 @@ int main(int argc, char* argv[]) {
|
||||
.admin_pubkey_override = {0}, // Empty string = not set
|
||||
.relay_privkey_override = {0}, // Empty string = not set
|
||||
.strict_port = 0, // 0 = allow port increment (default)
|
||||
.debug_level = 0 // 0 = no debug output (default)
|
||||
.debug_level = 0, // 0 = no debug output (default)
|
||||
.start_caching = 0, // 0 = don't auto-start caching service
|
||||
.reset_backfill = 0 // 0 = don't reset backfill progress
|
||||
};
|
||||
|
||||
// Parse command line arguments
|
||||
@@ -2565,6 +2569,12 @@ int main(int argc, char* argv[]) {
|
||||
} else if (strcmp(argv[i], "--strict-port") == 0) {
|
||||
// Strict port mode option
|
||||
cli_options.strict_port = 1;
|
||||
} else if (strcmp(argv[i], "--start-caching") == 0) {
|
||||
// Auto-start the caching service on startup
|
||||
cli_options.start_caching = 1;
|
||||
} else if (strcmp(argv[i], "--reset-backfill") == 0) {
|
||||
// Clear caching_backfill_progress before starting caching service
|
||||
cli_options.reset_backfill = 1;
|
||||
} else if (strncmp(argv[i], "--debug-level=", 14) == 0) {
|
||||
// Debug level option
|
||||
char* endptr;
|
||||
@@ -2956,6 +2966,30 @@ int main(int argc, char* argv[]) {
|
||||
// Runs on the main lws service thread via caching_inbox_poller_tick().
|
||||
caching_inbox_poller_init();
|
||||
|
||||
// Auto-start the caching service if requested via --start-caching.
|
||||
// Optionally reset backfill progress first if --reset-backfill was passed.
|
||||
if (cli_options.start_caching) {
|
||||
#ifdef DB_BACKEND_POSTGRES
|
||||
if (cli_options.reset_backfill) {
|
||||
DEBUG_INFO("CLI: resetting caching backfill progress (--reset-backfill)");
|
||||
if (db_exec_sql("DELETE FROM caching_backfill_progress") == 0) {
|
||||
DEBUG_INFO("CLI: caching_backfill_progress cleared");
|
||||
} else {
|
||||
DEBUG_WARN("CLI: failed to clear caching_backfill_progress");
|
||||
}
|
||||
}
|
||||
DEBUG_INFO("CLI: auto-starting caching service (--start-caching)");
|
||||
int caching_rc = caching_service_start();
|
||||
if (caching_rc == 0) {
|
||||
DEBUG_INFO("CLI: caching service started successfully");
|
||||
} else {
|
||||
DEBUG_ERROR("CLI: failed to start caching service (rc=%d)", caching_rc);
|
||||
}
|
||||
#else
|
||||
DEBUG_WARN("CLI: --start-caching requires PostgreSQL backend");
|
||||
#endif
|
||||
}
|
||||
|
||||
// Phase 5 strict mode: remove main-thread fallback to global DB handle.
|
||||
// Runtime DB access must go through thread-bound worker connections.
|
||||
// Ownership now resides in db_ops.c; no direct global handle mutation here.
|
||||
|
||||
+2
-2
@@ -13,8 +13,8 @@
|
||||
// Using CRELAY_ prefix to avoid conflicts with nostr_core_lib VERSION macros
|
||||
#define CRELAY_VERSION_MAJOR 2
|
||||
#define CRELAY_VERSION_MINOR 1
|
||||
#define CRELAY_VERSION_PATCH 21
|
||||
#define CRELAY_VERSION "v2.1.21"
|
||||
#define CRELAY_VERSION_PATCH 22
|
||||
#define CRELAY_VERSION "v2.1.22"
|
||||
|
||||
// Relay metadata (authoritative source for NIP-11 information)
|
||||
#define RELAY_NAME "C-Relay-PG"
|
||||
|
||||
Reference in New Issue
Block a user