| 168 | }; |
| 169 | |
| 170 | DistributedHeader readDistributedHeader(ReadBufferFromFile & in, Poco::Logger * log) |
| 171 | { |
| 172 | DistributedHeader distributed_header; |
| 173 | |
| 174 | UInt64 query_size; |
| 175 | readVarUInt(query_size, in); |
| 176 | |
| 177 | if (query_size == DBMS_DISTRIBUTED_SIGNATURE_HEADER) |
| 178 | { |
| 179 | /// Read the header as a string. |
| 180 | String header_data; |
| 181 | readStringBinary(header_data, in); |
| 182 | |
| 183 | /// Check the checksum of the header. |
| 184 | CityHash_v1_0_2::uint128 checksum; |
| 185 | readPODBinary(checksum, in); |
| 186 | assertChecksum(checksum, CityHash_v1_0_2::CityHash128(header_data.data(), header_data.size())); |
| 187 | |
| 188 | /// Read the parts of the header. |
| 189 | ReadBufferFromString header_buf(header_data); |
| 190 | |
| 191 | UInt64 initiator_revision; |
| 192 | readVarUInt(initiator_revision, header_buf); |
| 193 | if (DBMS_TCP_PROTOCOL_VERSION < initiator_revision) |
| 194 | { |
| 195 | LOG_WARNING(log, "ClickHouse shard version is older than ClickHouse initiator version. It may lack support for new features."); |
| 196 | } |
| 197 | |
| 198 | readStringBinary(distributed_header.insert_query, header_buf); |
| 199 | distributed_header.insert_settings.read(header_buf); |
| 200 | |
| 201 | if (header_buf.hasPendingData()) |
| 202 | distributed_header.client_info.read(header_buf, initiator_revision); |
| 203 | |
| 204 | if (header_buf.hasPendingData()) |
| 205 | { |
| 206 | readVarUInt(distributed_header.rows, header_buf); |
| 207 | readVarUInt(distributed_header.bytes, header_buf); |
| 208 | readStringBinary(distributed_header.block_header_string, header_buf); |
| 209 | } |
| 210 | |
| 211 | if (header_buf.hasPendingData()) |
| 212 | { |
| 213 | NativeBlockInputStream header_block_in(header_buf, DBMS_TCP_PROTOCOL_VERSION); |
| 214 | distributed_header.block_header = header_block_in.read(); |
| 215 | if (!distributed_header.block_header) |
| 216 | throw Exception(ErrorCodes::CANNOT_READ_ALL_DATA, "Cannot read header from the {} batch", in.getFileName()); |
| 217 | } |
| 218 | |
| 219 | /// Add handling new data here, for example: |
| 220 | /// |
| 221 | /// if (header_buf.hasPendingData()) |
| 222 | /// readVarUInt(my_new_data, header_buf); |
| 223 | /// |
| 224 | /// And note that it is safe, because we have checksum and size for header. |
| 225 | |
| 226 | return distributed_header; |
| 227 | } |
no test coverage detected