3737#include " core/ndd.hpp"
3838#include " auth.hpp"
3939#include " quant/common.hpp"
40- #include " cpu_compat_check/check_avx_compat.hpp"
41- #include " cpu_compat_check/check_arm_compat.hpp"
40+ #include " system_sanity/system_sanity.hpp"
4241
4342using ndd::quant::quantLevelToString;
4443using ndd::quant::stringToQuantLevel;
@@ -142,32 +141,6 @@ inline nlohmann::ordered_json make_index_info_payload(const IndexInfo& info) {
142141 return payload;
143142}
144143
145- /* *
146- * Checks if the CPU is compatible with all
147- * the instruction sets being used for x86, ARM and MAC Mxx
148- */
149- bool is_cpu_compatible () {
150- bool ret = true ;
151-
152- #if defined(USE_AVX2) && (defined(__x86_64__) || defined(_M_X64))
153- ret &= is_avx2_compatible ();
154- #endif // AVX2 checks
155-
156- #if defined(USE_AVX512) && (defined(__x86_64__) || defined(_M_X64))
157- ret &= is_avx512_compatible ();
158- #endif // AVX512 checks
159-
160- #if defined(USE_NEON)
161- ret &= is_neon_compatible ();
162- #endif
163-
164- #if defined(USE_SVE2)
165- ret &= is_sve2_compatible ();
166- #endif
167-
168- return ret;
169- }
170-
171144// Read file contents
172145std::string read_file (const std::string& path) {
173146 std::ifstream file (path, std::ios::binary);
@@ -233,9 +206,9 @@ int main(int argc, char** argv) {
233206 return 1 ;
234207 }
235208
236- if (!is_cpu_compatible ()) {
237- LOG_ERROR (1004 , " CPU is not compatible; server startup aborted " );
238- return 0 ;
209+ if (!run_startup_sanity_checks ()) {
210+ LOG_ERROR (1799 , " Server startup aborted due to failed sanity checks " );
211+ return 1 ;
239212 }
240213
241214 LOG_INFO (" SERVER_ID: " << settings::SERVER_ID);
@@ -253,6 +226,7 @@ int main(int argc, char** argv) {
253226 LOG_INFO (" DEFAULT_MAX_ELEMENTS_INCREMENT: " << settings::DEFAULT_MAX_ELEMENTS_INCREMENT);
254227 LOG_INFO (" DEFAULT_MAX_ELEMENTS_INCREMENT_TRIGGER: "
255228 << settings::DEFAULT_MAX_ELEMENTS_INCREMENT_TRIGGER);
229+ LOG_INFO (" MINIMUM_REQUIRED_DRAM_MB: " << settings::MINIMUM_REQUIRED_DRAM_MB);
256230
257231 // Path to React build directory
258232 // Get the executable's directory and resolve frontend/dist relative to it
@@ -263,7 +237,6 @@ int main(int argc, char** argv) {
263237
264238 // Initialize index manager with persistence config
265239 std::string data_dir = settings::DATA_DIR;
266- std::filesystem::create_directories (data_dir);
267240
268241 PersistenceConfig persistence_config{
269242 settings::SAVE_EVERY_N_UPDATES, // Save every n updates
@@ -282,10 +255,11 @@ int main(int argc, char** argv) {
282255
283256 // ========== GENERAL ==========
284257 // Health check endpoint (no auth required)
285- CROW_ROUTE (app, " /api/v1/health" ).methods (" GET" _method)([](const crow::request& req) {
258+ // CROW_ROUTE(app, "/api/v1/health").methods("GET"_method)([](const crow::request& req) {
259+ CROW_ROUTE (app, " /api/v1/health" ).methods (" GET" _method)([]() {
286260 crow::json::wvalue response (
287261 {{" status" , " ok" },
288- {" timestamp" , std::chrono::system_clock::now ().time_since_epoch ().count ()}});
262+ {" timestamp" , (std:: int64_t ) std::chrono::system_clock::now ().time_since_epoch ().count ()}});
289263 PRINT_LOG_TIME ();
290264 ndd::printSparseSearchDebugStats ();
291265 ndd::printSparseUpdateDebugStats ();
@@ -450,7 +424,7 @@ int main(int argc, char** argv) {
450424 body.has (" sparse_model" ) ? std::string (body[" sparse_model" ].s ()) : " None" ;
451425 const auto sparse_model = ndd::sparseScoringModelFromString (sparse_model_str);
452426 if (!sparse_model.has_value ()) {
453- LOG_WARN (1019 , index_id, " Invalid sparse_model: " << sparse_model_str);
427+ LOG_WARN (1025 , index_id, " Invalid sparse_model: " << sparse_model_str);
454428 return json_error (
455429 400 ,
456430 " Invalid sparse_model. Must be one of: None, default, endee_bm25" );
@@ -470,7 +444,7 @@ int main(int argc, char** argv) {
470444 index_manager.createIndex (index_id, config, UserType::Admin, size_in_millions);
471445 return crow::response (200 , " Index created successfully" );
472446 } catch (const std::runtime_error& e) {
473- LOG_WARN (1019 , index_id, " Create-index request failed: " << e.what ());
447+ LOG_WARN (1026 , index_id, " Create-index request failed: " << e.what ());
474448 return json_error (409 , e.what ());
475449 } catch (const std::exception& e) {
476450 return json_error_500 (
@@ -936,6 +910,10 @@ int main(int argc, char** argv) {
936910 // Verify content type is application/msgpack or application/json
937911 auto content_type = req.get_header_value (" Content-Type" );
938912
913+ if (is_disk_full ()){
914+ return json_error (400 , " Batch insertion aborted: Not enough storage space" );
915+ }
916+
939917 if (content_type == " application/json" ) {
940918 auto body = crow::json::load (req.body );
941919 if (!body) {
@@ -999,7 +977,14 @@ int main(int argc, char** argv) {
999977
1000978 try {
1001979 bool success = index_manager.addVectors (index_id, vectors);
1002- return crow::response (success ? 200 : 400 );
980+ if (!success) {
981+ LOG_WARN (1066 ,
982+ ctx.username ,
983+ index_name,
984+ " Insert request failed without detailed error from addVectors" );
985+ return json_error (400 , " Batch insertion failed" );
986+ }
987+ return crow::response (200 );
1003988 } catch (const std::runtime_error& e) {
1004989 LOG_WARN (1041 , ctx.username , index_name, " Insert request rejected: " << e.what ());
1005990 return json_error (400 , e.what ());
@@ -1017,13 +1002,27 @@ int main(int argc, char** argv) {
10171002 auto vectors = obj.as <std::vector<ndd::HybridVectorObject>>();
10181003 LOG_DEBUG (" Batch size (Hybrid): " << vectors.size ());
10191004 bool success = index_manager.addVectors (index_id, vectors);
1020- return crow::response (success ? 200 : 400 );
1005+ if (!success) {
1006+ LOG_WARN (1067 ,
1007+ ctx.username ,
1008+ index_name,
1009+ " Insert request failed without detailed error from addVectors" );
1010+ return json_error (400 , " Batch insertion failed" );
1011+ }
1012+ return crow::response (200 );
10211013 } catch (...) {
10221014 // Fallback to VectorObject
10231015 auto vectors = obj.as <std::vector<ndd::VectorObject>>();
10241016 LOG_DEBUG (" Batch size (Dense): " << vectors.size ());
10251017 bool success = index_manager.addVectors (index_id, vectors);
1026- return crow::response (success ? 200 : 400 );
1018+ if (!success) {
1019+ LOG_WARN (1068 ,
1020+ ctx.username ,
1021+ index_name,
1022+ " Insert request failed without detailed error from addVectors" );
1023+ return json_error (400 , " Batch insertion failed" );
1024+ }
1025+ return crow::response (200 );
10271026 }
10281027 } catch (const std::runtime_error& e) {
10291028 LOG_WARN (1042 , ctx.username , index_name, " Insert request rejected: " << e.what ());
0 commit comments