Datanode Data Block Workflow Dataxceiver

Source: Internet
Author: User
Tags ack socket

Dataxceviverserver:

Listens for block transport connection requests while controlling the number of block transfer requests made (the number of transfers at the same time cannot exceed maxxceivercount) and bandwidth consumption ( Bandwidth at the time of block transfer cannot exceed the predetermined value of Blocktransferthrottler.bytesperperiod). When a block transfer request is heard in run, a dataxceiver thread processing block transfer is turned on. When the system shuts down, the ServerSocket for the listening connection is turned off and the thread generated by Dataxceiver is closed, causing Dataxceiver to exit because of an error.

Blocktransferthrottler:

A bandwidth throttle that coordinates the bandwidth consumed by block transport. During a block transfer, if you have used more than the expected bandwidth to make it wait for a while, the bandwidth is not exhausted because of a block transfer.

The dataxceiver inherits from the runnable and is used to implement the block's sending and receiving. In run, the first version of the check, and then determine whether the current number of simultaneous transmission of the block more than the Dataxceiverserver.maxxceivercount value, if the operation failed. Then read the operation to be performed from the client op:

Op_write_block (80): Write data block

Op_read_block (81): Read data block

Op_read_metadata (82): Read data block meta-file

Op_replace_block (83): replacing a block of data

Op_copy_block (84): Copy a block of data

Op_block_checksum (85): Read Data block verification code

Call the appropriate method for processing according to this operation. After processing, close the stream and close the socket.

=============================================================

Read Operation Dataxceiver.readblock:

Receive Blockid,genstamp block timestamp in turn, startoffset block offset position, length to read the block size, clientname the name of the client requestor (non-empty string indicates that this is the client's write block operation, Otherwise, the active read block operation in Replaceblock).

Based on the information above, a Blockreader object is established, a op_status_success is sent to the requestor indicating the state of the operation, and then the Blockreader.sendblock is called to send the block to the requestor. Update Datanode.myMetrics.bytesRead, Datanode.myMetrics.blocksRead. Finally, the output stream and Blockreader are closed.

The Blockreader constructor is more complex because of its design to checksum. The approximate process is to get the input stream of the metadata (checksum) file, verify the metadata version, get checksum checksum, calculate the location where the block file and checksum file begins to read, and open the block data stream.


Blockreader.sendblock first sends Checksum.header to the requestor, then divides the block file into a maximum of maxchunksperpacket packets for sending, each packet size is pktsize, and then multiple surveys BLOCKREADER.SENDC Hunks (pktbuf,maxchunksperpacket,streamforsendchunks) sends the data packets out. Sending a 0 indicates the completion of sending a block after the send packet has ended. Then Blockreader.close () closes various resources. The sent traffic is counted during the sending of the package.



Blockreader.sendchunks (bytebuffer pkt, int maxchunks, outputstream out) first calculates the maximum number of chunks a packet can send, then Packetlen packet length, Offset of the start position of the packet in the block, the number of the SEQNO packet, whether the last packet was written to the PKT, and then read out the checksum data in the block metadata file into the PKT. Calculates the position of the block data in the PKT (after it is stored in the checksum data). The blockreader.blockinposition variable value is then used to determine whether the data can be sent to the block requester using FileChannel. If not, the block data is read into the BUF, and then the checksum is generated with the checksum of the read data and verified with the previously read block metadata file, and the BUF is sent to the requestor after the validation is successful. If you can, first send the checksum in buf, and then use FileChannel to send the data in the block file. Finally call Blocktransferthrottler.throttle for throttling control.

Note: Blockreader.blockinposition is used to determine if a filechannel can be opened, and if so, the packet is sent to the client based on this Filechannel.transferto method. 】

=============================================================

Write Operation Dataxceiver.writeblock:

Writing blocks involves backing up chunks of data to write blocks to multiple datanodes. These datanodes will be organized into a pipeline.

The client sends the block to the first Datanode on pipeline, which writes the block data locally and passes it to the next one. The response information returned by the subsequent block, together with its own operation result information, is then returned to the front. On pipeline, if a datanode has a subsequent node, it must wait until the subsequent node succeeds in answering the node before it can send an answer to it.

Dataxceiver.writeblock will first create three data streams mirrorout, Mirrorin, Replyout, sockets to the next DN, and blockreceiver for receiving blocks and write blocks.

DataOutputStream Mirrorout//stream to next target

DataInputStream Mirrorin//reply from next target

DataOutputStream Replyout//stream to Prev Target

Socket Mirrorsock//socket to next target

Blockreceiver Blockreceiver//responsible for data handling


Then call Blockreceiver.receiveblock to do the block operation. Close the stream and socket after the operation is complete.


Blockreceiver.receiveblock will start a packetresponder thread first, and then call Receivepacket until the block data is read. Then writing 0 to the next node indicates that the block write is complete. All responses waiting to packets are sent. Call Fsdataset for Finalizeblock. Finally close the Packetresponder thread.

Blockreceiver.receivepacket calls Blockreceiver.readnextpacket to receive a packet (which is ultimately called READTOBUF packet is read into BUF). The packet is then written to the next node (after the data is written to the next node, write a 0 to indicate the end of the block). A packet format is shown below:

Only pipeline the last node or the sender is Namenode, it is necessary to verify the data sent to Verifychunks. The block data and the block metadata file are then written to the TMP directory. A response is queued to the responder.ackqueue after the local write is completed in order to operate on the previous DN or client response block.

The Datanode on pipeline has a blockreceiver.packetresponder thread that sends a response message and a heartbeat keepalive up to one datanode or client.

The heartbeat keepalive mechanism on the pipeline is carried forward: the last Datanode D is sent to the previous Datanode C,c to receive a heartbeat message, just like B sending a heartbeat ...

Packetresponder.run reads a pipelineack from the next DN and gets the packet number seqno (which can be a heartbeat, error flag, packet identity). If it is a heartbeat, the ACK is echoed back to the previous DN. If it is packet, first read a packet from Ackqueue to verify that the packet.seqno is equal to the ack.seqno previously read (indicating the same block), if the packet is the last one in the block, Just use Notifynamenodereceivedblock to send notification to Namenode "all the changes to the Datanode operation, need to update the information 刡 Namenode", Call Finalizeblock at the same time to move the block and metadata files to current. Then from the previously read ack.replies plus the current operation status Op_status_success, wrapped into a pipelineack, write back to the previous DN or client.

After a successful packet operation from the previous DN or client, the packet (Seqno,lastpacketinblock) Adding to Packetresponder.ackqueue, Packetresponder removes packet from Ackqueue and learns to notify the previous DN or client of the pipeline's write packet. A pipelineack is sent up to a DN or client based on a write packet response message from the subsequent DN obtained from the next DN.

When Datanode receives the last packet, it calls Finalizeblock within Packetresponder.run to move the block to current, and calls Notifynamenodereceivedblock ( Block,datanode.empty_del_hint); Notifies the Namenode that the block has been written.

===============================================================

Read meta data file operations dataxceiver.readmetadata:<

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.