bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
SuperChunk.h
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of the BES
4
5// Copyright (c) 2020 OPeNDAP, Inc.
6// Author: Nathan Potter<ndp@opendap.org>
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Lesser General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21//
22// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23
24#ifndef HYRAX_GIT_SUPERCHUNK_H
25#define HYRAX_GIT_SUPERCHUNK_H
26
27#include <vector>
28#include <memory>
29#include <thread>
30#include <queue>
31#include <sstream>
32
33#include "Chunk.h"
34
35namespace dmrpp {
36
37// Forward Declaration
38class DmrppArray;
39
44class SuperChunk {
45// private
46 friend class SuperChunkTest;
47
48 std::string d_id;
49 DmrppArray *d_parent_array = nullptr;
50 std::shared_ptr<http::url> d_data_url;
51 std::vector<std::shared_ptr<Chunk>> d_chunks;
52 unsigned long long d_offset = 0;
53 unsigned long long d_size = 0;
54 bool d_is_read = false;
55 char *d_read_buffer = nullptr;
56
57 bool d_uses_fill_value{false};
58
59 bool non_contiguous_chunk{false};
60
61 bool is_contiguous(std::shared_ptr<Chunk> candidate_chunk);
62 void map_chunks_to_buffer();
63 void map_non_contiguous_chunks_to_buffer();
64 void read_aggregate_bytes();
65 void read_fill_value_chunk();
66
67public:
68 // Make the sc_id an uint64 and not a string - the code uses sstream to make the value. jhrg 5/7/22
69 explicit SuperChunk(const std::string &sc_id, DmrppArray *parent = nullptr) :
70 d_id(sc_id), d_parent_array(parent)
71 {}
72
73 virtual ~SuperChunk(){
74 delete[] d_read_buffer;
75 }
76
77 virtual std::string id() const { return d_id; }
78
79 virtual bool add_chunk(std::shared_ptr<Chunk> candidate_chunk);
80
81 std::shared_ptr<http::url> get_data_url() { return d_data_url; }
82 virtual unsigned long long get_size() const { return d_size; }
83 virtual unsigned long long get_offset() const { return d_offset; }
84
85 virtual void read() {
87 }
88
89 virtual void read_unconstrained() {
91 }
92
93 virtual void read_unconstrained_dio();
94
95
96 virtual void retrieve_data();
97 virtual void retrieve_data_dio();
98
99 virtual void process_child_chunks();
101
102 virtual bool empty() const { return d_chunks.empty(); }
103
104 void set_non_contiguous_chunk_flag(bool flag) { non_contiguous_chunk = flag; }
105 bool get_non_contiguous_chunk_flag() const { return non_contiguous_chunk;}
106 virtual bool add_chunk_non_contiguous(std::shared_ptr<Chunk> candidate_chunk, unsigned long long &end_pos);
107
108 std::string to_string(bool verbose) const;
109 virtual void dump(std::ostream & strm) const;
110};
111
116struct one_chunk_args {
117 std::thread::id parent_thread_id;
118 std::string parent_super_chunk_id;
119 std::shared_ptr<Chunk> chunk;
120 DmrppArray *array;
121 const vector<unsigned long long> &array_shape;
122
123 one_chunk_args(const std::string &sc_id, std::shared_ptr<Chunk> c, DmrppArray *a, const std::vector<unsigned long long> &a_s)
124 : parent_thread_id(std::this_thread::get_id()), parent_super_chunk_id(sc_id), chunk(std::move(c)), array(a), array_shape(a_s) {}
125};
126
132struct one_chunk_unconstrained_args {
133 std::thread::id parent_thread_id;
134 std::string parent_super_chunk_id;
135 std::shared_ptr<Chunk> chunk;
136 DmrppArray *array;
137 const vector<unsigned long long> &array_shape;
138 const vector<unsigned long long> &chunk_shape;
139
140 one_chunk_unconstrained_args(const std::string &sc_id, std::shared_ptr<Chunk> c, DmrppArray *a, const std::vector<unsigned long long> &a_s,
141 const std::vector<unsigned long long> &c_s)
142 : parent_thread_id(std::this_thread::get_id()), parent_super_chunk_id(sc_id), chunk(std::move(c)),
143 array(a), array_shape(a_s), chunk_shape(c_s) {}
144};
145
146void process_chunks_concurrent(
147 const string &super_chunk_id,
148 std::queue<shared_ptr<Chunk>> &chunks,
149 DmrppArray *array,
150 const std::vector<unsigned long long> &shape );
151
152void process_chunks_unconstrained_concurrent(
153 const string &super_chunk_id,
154 std::queue<std::shared_ptr<Chunk>> &chunks,
155 const std::vector<unsigned long long> &chunk_shape,
156 DmrppArray *array,
157 const std::vector<unsigned long long> &array_shape);
158
159void process_chunks_unconstrained_concurrent_dio(
160 const string &super_chunk_id,
161 std::queue<std::shared_ptr<Chunk>> &chunks,
162 const std::vector<unsigned long long> &chunk_shape,
163 DmrppArray *array,
164 const std::vector<unsigned long long> &array_shape);
165
166} // namespace dmrpp
167
168#endif // HYRAX_GIT_SUPERCHUNK_H
Extend libdap::Array so that a handler can read data using a DMR++ file.
Definition DmrppArray.h:77
virtual void retrieve_data()
Cause the SuperChunk and all of it's subordinate Chunks to be read.
virtual bool add_chunk(std::shared_ptr< Chunk > candidate_chunk)
Attempts to add a new Chunk to this SuperChunk.
std::string to_string(bool verbose) const
Makes a string representation of the SuperChunk.
virtual void dump(std::ostream &strm) const
Writes the to_string() output to the stream strm.
virtual void process_child_chunks()
Reads the SuperChunk, inflates/de-shuffles the subordinate chunks as required and copies the values i...
virtual void process_child_chunks_unconstrained()
Reads the SuperChunk, inflates/deshuffles the subordinate chunks as required and copies the values in...
STL class.