SwatDB
Loading...
Searching...
No Matches
parallelHashJoin.h
Go to the documentation of this file.
1/*
2 * SwatDB
3 *
4 * @authors: See Contributors.doc for code contributors
5 *
6 * Copyright (c) 2020 Swarthmore College Computer Science Department
7 * Swarthmore PA, Professors Tia Newhall, Ameet Soni
8 */
9
10#ifndef _SWATDB_PARALLELHASHJOIN_H_
11#define _SWATDB_PARALLELHASHJOIN_H_
12
18#include <string>
19#include <vector>
20#include <thread>
21#include <mutex>
22#include <condition_variable>
23#include "swatdb_types.h"
24#include "hashjoin.h"
25
26class FileManager;
27class Catalog;
28class Schema;
29class File;
30class RelationFile;
31class HeapFileScanner;
33class HeapFile;
34class Record;
35class Data;
36class Key;
37
43class ParallelHashJoin : public HashJoin {
44
45 public:
46
70 ParallelHashJoin(FileId outer_id, FileId inner_id, FileId result_id,
71 std::vector<FieldId> outer_fields,
72 std::vector<FieldId> inner_fields,
73 std::uint32_t num_buckets,
74 std::uint32_t num_threads,
75 std::string temp_path, Catalog *catalog, BufferManager *buf_mgr,
77
82
91
92 private:
93
94
98 std::uint32_t num_threads;
99
100 //TODO replace
101 std::uint32_t result_num;
102
106 std::mutex *mtx_table;
107
111 std::mutex mtx;
112
116 std::condition_variable cv;
117
121 std::uint32_t tcount;
122
127 std::exception_ptr thd_exc_ptr;
128
133 std::mutex exc_mtx;
134
138 std::vector<std::thread> threads;
139
140
149 void _firstHash(std::uint32_t tid, bool is_outer);
150
156 void _secondHash(std::uint32_t tid, std::uint32_t n_threads);
157
166 RecordId _parallelPart1(Record* record, bool is_outer, BlockHeapFileScanner *scanner);
167
174 void _barrier(std::uint32_t n_threads);
175
184 void _parallelRun(std::uint32_t tid);
185
186};
187
188#endif
Definition blockheapfilescanner.h:35
Definition bufmgr.h:121
Definition catalog.h:161
Definition data.h:26
Definition filemgr.h:32
Definition file.h:45
Definition hashjoin.h:42
BufferManager * buf_mgr
Definition hashjoin.h:94
FileManager * file_mgr
Definition hashjoin.h:99
std::string temp_path
Holds the path to which the temp files should be saved. "/local/" is recommended for performance.
Definition hashjoin.h:127
std::uint32_t num_buckets
Definition hashjoin.h:116
Definition heapfilescanner.h:39
Definition heapfile.h:76
std::vector< FieldId > inner_fields
Definition join.h:83
std::vector< FieldId > outer_fields
Definition join.h:78
Definition key.h:38
Definition parallelHashJoin.h:43
void _secondHash(std::uint32_t tid, std::uint32_t n_threads)
Performs the second hashing of each relation for the second step of hash join.
std::uint32_t tcount
Definition parallelHashJoin.h:121
std::exception_ptr thd_exc_ptr
Definition parallelHashJoin.h:127
ParallelHashJoin(FileId outer_id, FileId inner_id, FileId result_id, std::vector< FieldId > outer_fields, std::vector< FieldId > inner_fields, std::uint32_t num_buckets, std::uint32_t num_threads, std::string temp_path, Catalog *catalog, BufferManager *buf_mgr, FileManager *file_mgr)
Constructor for the join operater using a hash join algorithm. Sets up the state for a single join op...
void _barrier(std::uint32_t n_threads)
Helper function for _parallelRun which has threads wait until all threads have called this function.
RecordId _parallelPart1(Record *record, bool is_outer, BlockHeapFileScanner *scanner)
Performs the main looping functionality for first hash.
void _firstHash(std::uint32_t tid, bool is_outer)
Performs the initial hashing of each relation for the first step of hash join.
std::uint32_t num_threads
Definition parallelHashJoin.h:98
std::mutex * mtx_table
Definition parallelHashJoin.h:106
void runOperation()
Performs the join operation using the hash join alogrithm.
std::mutex mtx
Definition parallelHashJoin.h:111
std::vector< std::thread > threads
Definition parallelHashJoin.h:138
std::mutex exc_mtx
Definition parallelHashJoin.h:133
~ParallelHashJoin()
Destructor for hashjoin class.
std::condition_variable cv
Definition parallelHashJoin.h:116
void _parallelRun(std::uint32_t tid)
Performs the parallel functionality of parallel run, to be called by all threads.
Definition record.h:34
Definition relationfile.h:32
Definition schema.h:37
Definition swatdb_types.h:70
std::uint32_t FileId
Definition swatdb_types.h:33