@@ -97,6 +97,13 @@ class HSReplApplication : public homestore::ReplApplication {
9797//
9898// This should assert if we can not initialize HomeStore.
9999//
100+ DevType HSHomeObject::get_device_type (string const & devname) {
101+ const iomgr::drive_type dtype = iomgr::DriveInterface::get_drive_type (devname);
102+ if (dtype == iomgr::drive_type::block_hdd || dtype == iomgr::drive_type::file_on_hdd) { return DevType::HDD; }
103+ if (dtype == iomgr::drive_type::file_on_nvme || dtype == iomgr::drive_type::block_nvme) { return DevType::NVME; }
104+ return DevType::UNSUPPORTED;
105+ }
106+
100107void HSHomeObject::init_homestore () {
101108 auto app = _application.lock ();
102109 RELEASE_ASSERT (app, " HomeObjectApplication lifetime unexpected!" );
@@ -115,9 +122,27 @@ void HSHomeObject::init_homestore() {
115122 LOGI (" Initialize and start HomeStore with app_mem_size = {}" , homestore::in_bytes (app_mem_size));
116123
117124 std::vector< homestore::dev_info > device_info;
118- for (auto const & path : app->devices ()) {
119- device_info.emplace_back (std::filesystem::canonical (path).string (), homestore::HSDevType::Data);
125+ bool has_data_dev = false ;
126+ bool has_fast_dev = false ;
127+ for (auto const & dev : app->devices ()) {
128+ auto input_dev_type = dev.type ;
129+ auto detected_type = get_device_type (dev.path .string ());
130+ LOGD (" Device {} detected as {}" , dev.path .string (), detected_type);
131+ auto final_type = (dev.type == DevType::AUTO_DETECT) ? detected_type : input_dev_type;
132+ if (final_type == DevType::UNSUPPORTED) {
133+ LOGW (" Device {} is not supported, skipping" , dev.path .string ());
134+ continue ;
135+ }
136+ if (input_dev_type != DevType::AUTO_DETECT && detected_type != final_type) {
137+ LOGW (" Device {} detected as {}, but input type is {}, using input type" , dev.path .string (), detected_type,
138+ input_dev_type);
139+ }
140+ auto hs_type = (final_type == DevType::HDD) ? homestore::HSDevType::Data : homestore::HSDevType::Fast;
141+ if (hs_type == homestore::HSDevType::Data) { has_data_dev = true ; }
142+ if (hs_type == homestore::HSDevType::Fast) { has_fast_dev = true ; }
143+ device_info.emplace_back (std::filesystem::canonical (dev.path ).string (), hs_type);
120144 }
145+ RELEASE_ASSERT (device_info.size () != 0 , " No supported devices found!" );
121146
122147 chunk_selector_ = std::make_shared< HeapChunkSelector >();
123148 using namespace homestore ;
@@ -134,17 +159,39 @@ void HSHomeObject::init_homestore() {
134159 RELEASE_ASSERT (!_our_id.is_nil (), " Received no SvcId and need FORMAT!" );
135160 LOGW (" We are starting for the first time on [{}], Formatting!!" , to_string (_our_id));
136161
137- HomeStore::instance ()->format_and_start ({
138- {HS_SERVICE::META, hs_format_params{.size_pct = 5.0 }},
139- {HS_SERVICE::LOG, hs_format_params{.size_pct = 10.0 , .chunk_size = 32 * Mi}},
140- {HS_SERVICE::REPLICATION,
141- hs_format_params{.size_pct = 79.0 ,
142- .num_chunks = 65000 ,
143- .block_size = _data_block_size,
144- .alloc_type = blk_allocator_type_t ::append,
145- .chunk_sel_type = chunk_selector_type_t ::CUSTOM}},
146- {HS_SERVICE::INDEX, hs_format_params{.size_pct = 5.0 }},
147- });
162+ if (has_data_dev && has_fast_dev) {
163+ // Hybrid mode
164+ LOGD (" Has both Data and Fast, running with Hybrid mode" );
165+ HomeStore::instance ()->format_and_start ({
166+ {HS_SERVICE::META, hs_format_params{.dev_type = HSDevType::Fast, .size_pct = 9.0 , .num_chunks = 64 }},
167+ {HS_SERVICE::LOG,
168+ hs_format_params{.dev_type = HSDevType::Fast, .size_pct = 45.0 , .chunk_size = 32 * Mi}},
169+ {HS_SERVICE::INDEX, hs_format_params{.dev_type = HSDevType::Fast, .size_pct = 45.0 , .num_chunks = 128 }},
170+ {HS_SERVICE::REPLICATION,
171+ hs_format_params{.dev_type = HSDevType::Data,
172+ .size_pct = 99.0 ,
173+ .num_chunks = 60000 ,
174+ .block_size = _data_block_size,
175+ .alloc_type = blk_allocator_type_t ::append,
176+ .chunk_sel_type = chunk_selector_type_t ::CUSTOM}},
177+ });
178+ } else {
179+ auto run_on_type = has_fast_dev ? homestore::HSDevType::Fast : homestore::HSDevType::Data;
180+ LOGD (" Running with Single mode, all service on {}" , run_on_type);
181+ HomeStore::instance ()->format_and_start ({
182+ // FIXME: this is to work around the issue in HS that varsize allocator doesnt work with small chunk size.
183+ {HS_SERVICE::META, hs_format_params{.dev_type = run_on_type, .size_pct = 5.0 , .num_chunks = 1 }},
184+ {HS_SERVICE::LOG, hs_format_params{.dev_type = run_on_type, .size_pct = 10.0 , .chunk_size = 32 * Mi}},
185+ {HS_SERVICE::INDEX, hs_format_params{.dev_type = run_on_type, .size_pct = 5.0 , .num_chunks = 1 }},
186+ {HS_SERVICE::REPLICATION,
187+ hs_format_params{.dev_type = run_on_type,
188+ .size_pct = 79.0 ,
189+ .num_chunks = 60000 ,
190+ .block_size = _data_block_size,
191+ .alloc_type = blk_allocator_type_t ::append,
192+ .chunk_sel_type = chunk_selector_type_t ::CUSTOM}},
193+ });
194+ }
148195
149196 // Create a superblock that contains our SvcId
150197 auto svc_sb = homestore::superblk< svc_info_superblk_t >(_svc_meta_name);
0 commit comments