OmniSciDB  c07336695a
StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER > Class Template Reference

#include <StorageIOFacility.h>

Classes

struct  DeleteTransactionParameters
 
struct  MethodSelector
 
class  TransactionParameters
 
class  UpdateTransactionParameters
 

Public Types

using ExecutorType = typename EXECUTOR_TRAITS::ExecutorType
 
using CatalogType = typename EXECUTOR_TRAITS::CatalogType
 
using FragmentUpdaterType = FRAGMENT_UPDATER
 
using UpdateCallback = typename FragmentUpdaterType::Callback
 
using IOFacility = IO_FACET
 
using TableDescriptorType = typename EXECUTOR_TRAITS::TableDescriptorType
 
using DeleteVictimOffsetList = typename IOFacility::DeleteVictimOffsetList
 
using UpdateTargetOffsetList = typename IOFacility::UpdateTargetOffsetList
 
using UpdateTargetTypeList = typename IOFacility::UpdateTargetTypeList
 
using UpdateTargetColumnNamesList = typename IOFacility::UpdateTargetColumnNamesList
 
using UpdateTargetColumnNameType = typename UpdateTargetColumnNamesList::value_type
 
using ColumnValidationFunction = typename IOFacility::ColumnValidationFunction
 
using StringSelector = Experimental::MetaTypeClass< Experimental::String >
 
using NonStringSelector = Experimental::UncapturedMetaTypeClass
 

Public Member Functions

 StorageIOFacility (ExecutorType *executor, CatalogType const &catalog)
 
ColumnValidationFunction yieldColumnValidator (TableDescriptorType const *table_descriptor)
 
UpdateCallback yieldUpdateCallback (UpdateTransactionParameters &update_parameters)
 
UpdateCallback yieldDeleteCallback (DeleteTransactionParameters &delete_parameters)
 

Private Member Functions

int normalized_cpu_threads () const
 

Private Attributes

ExecutorTypeexecutor_
 
CatalogType const & catalog_
 

Detailed Description

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
class StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >

Definition at line 102 of file StorageIOFacility.h.

Member Typedef Documentation

◆ CatalogType

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
using StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::CatalogType = typename EXECUTOR_TRAITS::CatalogType

Definition at line 105 of file StorageIOFacility.h.

◆ ColumnValidationFunction

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
using StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::ColumnValidationFunction = typename IOFacility::ColumnValidationFunction

Definition at line 115 of file StorageIOFacility.h.

◆ DeleteVictimOffsetList

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
using StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::DeleteVictimOffsetList = typename IOFacility::DeleteVictimOffsetList

Definition at line 110 of file StorageIOFacility.h.

◆ ExecutorType

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
using StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::ExecutorType = typename EXECUTOR_TRAITS::ExecutorType

Definition at line 104 of file StorageIOFacility.h.

◆ FragmentUpdaterType

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
using StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::FragmentUpdaterType = FRAGMENT_UPDATER

Definition at line 106 of file StorageIOFacility.h.

◆ IOFacility

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
using StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::IOFacility = IO_FACET

Definition at line 108 of file StorageIOFacility.h.

◆ NonStringSelector

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
using StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::NonStringSelector = Experimental::UncapturedMetaTypeClass

Definition at line 118 of file StorageIOFacility.h.

◆ StringSelector

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
using StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::StringSelector = Experimental::MetaTypeClass<Experimental::String>

Definition at line 117 of file StorageIOFacility.h.

◆ TableDescriptorType

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
using StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::TableDescriptorType = typename EXECUTOR_TRAITS::TableDescriptorType

Definition at line 109 of file StorageIOFacility.h.

◆ UpdateCallback

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
using StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::UpdateCallback = typename FragmentUpdaterType::Callback

Definition at line 107 of file StorageIOFacility.h.

◆ UpdateTargetColumnNamesList

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
using StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::UpdateTargetColumnNamesList = typename IOFacility::UpdateTargetColumnNamesList

Definition at line 113 of file StorageIOFacility.h.

◆ UpdateTargetColumnNameType

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
using StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::UpdateTargetColumnNameType = typename UpdateTargetColumnNamesList::value_type

Definition at line 114 of file StorageIOFacility.h.

◆ UpdateTargetOffsetList

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
using StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::UpdateTargetOffsetList = typename IOFacility::UpdateTargetOffsetList

Definition at line 111 of file StorageIOFacility.h.

◆ UpdateTargetTypeList

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
using StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::UpdateTargetTypeList = typename IOFacility::UpdateTargetTypeList

Definition at line 112 of file StorageIOFacility.h.

Constructor & Destructor Documentation

◆ StorageIOFacility()

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::StorageIOFacility ( ExecutorType executor,
CatalogType const &  catalog 
)
inline

Definition at line 179 of file StorageIOFacility.h.

180  : executor_(executor), catalog_(catalog) {}
ExecutorType * executor_
CatalogType const & catalog_

Member Function Documentation

◆ normalized_cpu_threads()

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
int StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::normalized_cpu_threads ( ) const
inlineprivate

Definition at line 191 of file StorageIOFacility.h.

191 { return cpu_threads() / 2; }
int cpu_threads()
Definition: thread_count.h:23

◆ yieldColumnValidator()

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
ColumnValidationFunction StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::yieldColumnValidator ( TableDescriptorType const *  table_descriptor)
inline

Definition at line 182 of file StorageIOFacility.h.

183  {
184  return IOFacility::yieldColumnValidator(catalog_, table_descriptor);
185  }
CatalogType const & catalog_

◆ yieldDeleteCallback()

template<typename EXECUTOR_TRAITS , typename IO_FACET , typename FRAGMENT_UPDATER >
StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::UpdateCallback StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::yieldDeleteCallback ( DeleteTransactionParameters delete_parameters)

Definition at line 344 of file StorageIOFacility.h.

345  {
346  using RowProcessingFuturesVector = std::vector<std::future<uint64_t>>;
347 
348  auto callback = [this,
349  &delete_parameters](FragmentUpdaterType const& update_log) -> void {
350  auto rows_per_column = update_log.getEntryCount();
351  if (rows_per_column == 0) {
352  return;
353  }
354  DeleteVictimOffsetList victim_offsets(rows_per_column);
355 
356  auto complete_row_block_size = rows_per_column / normalized_cpu_threads();
357  auto partial_row_block_size = rows_per_column % normalized_cpu_threads();
358  auto usable_threads = normalized_cpu_threads();
359 
360  if (UNLIKELY(rows_per_column < (unsigned)normalized_cpu_threads())) {
361  complete_row_block_size = rows_per_column;
362  partial_row_block_size = 0;
363  usable_threads = 1;
364  }
365 
366  auto process_rows = [&update_log, &victim_offsets](uint64_t row_start,
367  uint64_t row_count) -> uint64_t {
368  uint64_t rows_processed = 0;
369 
370  for (uint64_t row_index = row_start; row_index < (row_start + row_count);
371  row_index++, rows_processed++) {
372  auto const row(update_log.getEntryAt(row_index));
373  __builtin_prefetch(row.data(), 0, 0);
374 
375  CHECK(!row.empty());
376  auto terminal_column_iter = std::prev(row.end());
377  const auto scalar_tv = boost::get<ScalarTargetValue>(&*terminal_column_iter);
378  CHECK(scalar_tv);
379 
380  uint64_t fragment_offset =
381  static_cast<uint64_t>(*(boost::get<int64_t>(scalar_tv)));
382  victim_offsets[row_index] = fragment_offset;
383  }
384  return rows_processed;
385  };
386 
387  auto get_row_index = [complete_row_block_size](uint64_t thread_index) -> uint64_t {
388  return thread_index * complete_row_block_size;
389  };
390 
391  RowProcessingFuturesVector row_processing_futures;
392  row_processing_futures.reserve(usable_threads);
393 
394  for (unsigned i = 0; i < (unsigned)usable_threads; i++) {
395  row_processing_futures.emplace_back(
396  std::async(std::launch::async,
397  std::forward<decltype(process_rows)>(process_rows),
398  get_row_index(i),
399  complete_row_block_size));
400  }
401  if (partial_row_block_size) {
402  row_processing_futures.emplace_back(
403  std::async(std::launch::async,
404  std::forward<decltype(process_rows)>(process_rows),
405  get_row_index(usable_threads),
406  partial_row_block_size));
407  }
408 
409  uint64_t rows_processed(0);
410  for (auto& t : row_processing_futures) {
411  t.wait();
412  rows_processed += t.get();
413  }
414 
415  IOFacility::deleteColumns(catalog_,
416  update_log.getPhysicalTableId(),
417  update_log.getFragmentId(),
418  victim_offsets,
419  update_log.getColumnType(0),
420  delete_parameters.getTransactionTracker());
421  };
422  return callback;
423 }
typename IOFacility::DeleteVictimOffsetList DeleteVictimOffsetList
FRAGMENT_UPDATER FragmentUpdaterType
int normalized_cpu_threads() const
#define UNLIKELY(x)
Definition: likely.h:20
CatalogType const & catalog_
#define CHECK(condition)
Definition: Logger.h:187

◆ yieldUpdateCallback()

template<typename EXECUTOR_TRAITS , typename IO_FACET , typename FRAGMENT_UPDATER >
StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::UpdateCallback StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::yieldUpdateCallback ( UpdateTransactionParameters update_parameters)

Definition at line 199 of file StorageIOFacility.h.

200  {
201  using OffsetVector = std::vector<uint64_t>;
202  using ScalarTargetValueVector = std::vector<ScalarTargetValue>;
203  using RowProcessingFuturesVector = std::vector<std::future<uint64_t>>;
204 
205  if (update_parameters.isVarlenUpdateRequired()) {
206  auto callback = [this,
207  &update_parameters](FragmentUpdaterType const& update_log) -> void {
208  std::vector<const ColumnDescriptor*> columnDescriptors;
209  std::vector<TargetMetaInfo> sourceMetaInfos;
210 
211  for (size_t idx = 0; idx < update_parameters.getUpdateColumnNames().size(); idx++) {
212  auto& column_name = update_parameters.getUpdateColumnNames()[idx];
213  auto target_column =
214  catalog_.getMetadataForColumn(update_log.getPhysicalTableId(), column_name);
215  columnDescriptors.push_back(target_column);
216  sourceMetaInfos.push_back(update_parameters.getTargetsMetaInfo()[idx]);
217  }
218 
219  auto td = catalog_.getMetadataForTable(update_log.getPhysicalTableId());
220  auto* fragmenter = td->fragmenter;
221  CHECK(fragmenter);
222 
223  fragmenter->updateColumns(
224  &catalog_,
225  td,
226  update_log.getFragmentId(),
227  sourceMetaInfos,
228  columnDescriptors,
229  update_log,
230  update_parameters.getUpdateColumnCount(), // last column of result set
232  update_parameters.getTransactionTracker());
233  };
234  return callback;
235 
236  } else {
237  auto callback = [this,
238  &update_parameters](FragmentUpdaterType const& update_log) -> void {
239  auto rows_per_column = update_log.getEntryCount();
240  if (rows_per_column == 0) {
241  return;
242  }
243 
244  OffsetVector column_offsets(rows_per_column);
245  ScalarTargetValueVector scalar_target_values(rows_per_column);
246 
247  auto complete_row_block_size = rows_per_column / normalized_cpu_threads();
248  auto partial_row_block_size = rows_per_column % normalized_cpu_threads();
249  auto usable_threads = normalized_cpu_threads();
250  if (UNLIKELY(rows_per_column < (unsigned)normalized_cpu_threads())) {
251  complete_row_block_size = rows_per_column;
252  partial_row_block_size = 0;
253  usable_threads = 1;
254  }
255 
256  auto process_rows =
257  [&update_log, &update_parameters, &column_offsets, &scalar_target_values](
258  auto type_tag,
259  uint64_t column_index,
260  uint64_t row_start,
261  uint64_t row_count) -> uint64_t {
262  uint64_t rows_processed = 0;
263  for (uint64_t row_index = row_start; row_index < (row_start + row_count);
264  row_index++, rows_processed++) {
265  constexpr auto get_entry_method_sel(MethodSelector::getEntryAt(type_tag));
266  auto const row((update_log.*get_entry_method_sel)(row_index));
267 
268  CHECK(!row.empty());
269  CHECK(row.size() == update_parameters.getUpdateColumnCount() + 1);
270 
271  auto terminal_column_iter = std::prev(row.end());
272  const auto frag_offset_scalar_tv =
273  boost::get<ScalarTargetValue>(&*terminal_column_iter);
274  CHECK(frag_offset_scalar_tv);
275 
276  column_offsets[row_index] =
277  static_cast<uint64_t>(*(boost::get<int64_t>(frag_offset_scalar_tv)));
278  scalar_target_values[row_index] =
279  boost::get<ScalarTargetValue>(row[column_index]);
280  }
281  return rows_processed;
282  };
283 
284  auto get_row_index = [complete_row_block_size](uint64_t thread_index) -> uint64_t {
285  return (thread_index * complete_row_block_size);
286  };
287 
288  // Iterate over each column
289  for (decltype(update_parameters.getUpdateColumnCount()) column_index = 0;
290  column_index < update_parameters.getUpdateColumnCount();
291  column_index++) {
292  RowProcessingFuturesVector row_processing_futures;
293  row_processing_futures.reserve(usable_threads);
294 
295  auto thread_launcher = [&](auto const& type_tag) {
296  for (unsigned i = 0; i < static_cast<unsigned>(usable_threads); i++) {
297  row_processing_futures.emplace_back(
298  std::async(std::launch::async,
299  std::forward<decltype(process_rows)>(process_rows),
300  type_tag,
301  column_index,
302  get_row_index(i),
303  complete_row_block_size));
304  }
305  if (partial_row_block_size) {
306  row_processing_futures.emplace_back(
307  std::async(std::launch::async,
308  std::forward<decltype(process_rows)>(process_rows),
309  type_tag,
310  column_index,
311  get_row_index(usable_threads),
312  partial_row_block_size));
313  }
314  };
315 
316  if (!update_log.getColumnType(column_index).is_string()) {
317  thread_launcher(NonStringSelector());
318  } else {
319  thread_launcher(StringSelector());
320  }
321 
322  uint64_t rows_processed(0);
323  for (auto& t : row_processing_futures) {
324  t.wait();
325  rows_processed += t.get();
326  }
327 
328  IOFacility::updateColumn(catalog_,
329  update_log.getPhysicalTableId(),
330  update_parameters.getUpdateColumnNames()[column_index],
331  update_log.getFragmentId(),
332  column_offsets,
333  scalar_target_values,
334  update_log.getColumnType(column_index),
335  update_parameters.getTransactionTracker());
336  }
337  };
338  return callback;
339  }
340 }
FRAGMENT_UPDATER FragmentUpdaterType
Experimental::MetaTypeClass< Experimental::String > StringSelector
int normalized_cpu_threads() const
#define UNLIKELY(x)
Definition: likely.h:20
Experimental::UncapturedMetaTypeClass NonStringSelector
CatalogType const & catalog_
#define CHECK(condition)
Definition: Logger.h:187
static constexpr auto getEntryAt(StringSelector)

Member Data Documentation

◆ catalog_

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
CatalogType const& StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::catalog_
private

Definition at line 194 of file StorageIOFacility.h.

◆ executor_

template<typename EXECUTOR_TRAITS, typename IO_FACET = DefaultIOFacet<>, typename FRAGMENT_UPDATER = UpdateLogForFragment>
ExecutorType* StorageIOFacility< EXECUTOR_TRAITS, IO_FACET, FRAGMENT_UPDATER >::executor_
private

Definition at line 193 of file StorageIOFacility.h.


The documentation for this class was generated from the following file: