1024programmer Java Use Java simulation to implement disk array raid levels 0, 1, 3, 5, 6, 01, 10

Use Java simulation to implement disk array raid levels 0, 1, 3, 5, 6, 01, 10

Table of contents

  • 1. Instructions for use
  • 2. Overall design
  • 3. Operation screenshots
  • 4. Detailed design
    • 4.1raid0
    • 4.2raid1
    • 4.3raid3
    • 4.4raid5
    • 4.5raid6
    • 4.6raid01
    • 4.7raid10
  • 5. Source code

1. Instructions for use

The development environment of this program is the Windows operating system Eclipse software – developed using Java language. When using, open the project file and run Main.java under the raidMain package. According to the prompts, enter the file to be written “full path of the file” and the file to be read. The entered file path indicates file reading. The saved path “contains the file name to be read” and the file can be restored. The disk “folder” used by each disk array level data is different. For example, the main disk path of raid0 is disk/raid0 and raid6 is disk/raid6. The other disk/read and disk/read are used to demonstrate the file path for writing and reading. Of course, you can also choose other files for operation. Data when the disk is damaged when raid3, 5, and 6 are not completed. Restoration: After writing, I still found that there were still big problems with the program structure. However, the changes took a lot of time and I just let it go.

2. Overall design

Disks are simulated using folders. The stored data are files of any type. The number of file strips is divided according to the number of corresponding storage disks. There are Several data storage disks are divided into several parts. In order to identify which block of the original file the file block belongs to when reading the file and facilitate reorganization, the file is added after the file name. The starting position in the original file. In the Main.java class at the program entrance, you can select the corresponding disk array by entering commands “The disks of each disk array are not shared” to facilitate file management. Enter the corresponding disk array and perform up to four functions – writing files to the disk array, reading files from the disk array, recovering data when the disk in the disk array is damaged, exiting the disk array and returning to the selected disk. Array menu function.
Insert picture description here

3. Run screenshot

Insert picture description here

4. Detailed design

raidMain in the bag Main.java is the program entry class – the main method outputs the menu items and then the scanner input options. Use the switch-case structure to determine which raid level to use and create a new object of the corresponding class. The start method also passes in the scanner object. Used to get console input. If you create a new scanner object in another object, this scanner object will not be closed. If you do not close it, there will be a warning. If you close it, the scanner console input of another object will report an error. And input before and after. The data types should be kept consistent – here the console reads all string types. Entering other characters other than 0-7 will prompt you to enter the correct command and re-enter. If you enter 0, the input stream will be closed and the program will exit.

4.1raid0

If you enter 1, enter raid0. In the start method of the RAID0Main class, pass in the scanner object ,define the parent path where all disks in raid0 are located, and use the list method of the file object to list and search all the disks in the path one by one, add and save to the arraylist object,Then write the function to be executed in the while loop and use the switch-case structure to make a judgment,1 Write to the disk array;2 Read the data from the disk array& #xff1b;0Exit and return to the previous main menu, select the disk array level,Enter other and you will be prompted to enter the correct command.
Insert picture description here

If you enter 1,, you will be asked to enter the file path to be uploaded and use the path to create a file object to determine whether the file exists& #xff0c; If it does not exist, it will prompt that the file does not exist and jump out of the switch-case structure directly. Otherwise, use the disk path of the disk array and the uploaded file path to create a RAID0Write object, and create a new multi-thread based on the number of disks. Data writing.
RAID0Write implements the Runnable interface for the class that writes to the disk array. In the constructor, the arraylist object of each disk location and the file path to be written are passed in, and the initialize function is called to initialize. The initialization function mainly uses the number of disks to calculate the byte length of the file. The file byte length that should be stored on each disk is “average access” and the excess is placed on the last disk. At the same time, the size of the file strip except the last one is also saved.�A file that generates parity codes can be executed.
Insert picture description here

4.4raid5

If you enter 4,, enter raid5. raid5 puts the corresponding parity code information of all files on each disk evenly,So the idea is similar to raid3,When initializing the disk path, first specify any disk to store the parity code, #xff0c;Others are data disks. Every time a file is written to the disk array, the check code information of the file is written to the check code disk at that time, and then the disk path stored in the check code disk is replaced with the first disk path of the data disk. Then add the replaced path to the end of the dynamic array of data disk paths and delete the first path. It is equivalent to each disk taking turns to do the parity code.
Insert image description here

4.5raid6

If you enter 5,, enter raid6. The difference between raid6 and raid5 is that in the former, the same or different types of check code files are stored on two disks – parity check codes are used here. Reading data is the same as raid5 – traverse all the files on the disk to find the files you want to read and reassemble them. For writing to the disk array, the other ideas are the same. It just gives the parity check code disk digit 2 at the beginning. Then every time the file is written, the check code information is written here. Two disks,Then move these two disks to the dynamic array of the data disk,The data disk takes turns to use the two as check code storage disks as the check code storage location for the next file. ,This cycle repeats.
Insert image description here

4.6raid01

If you enter 6, enter raid01. The disk path of this disk array is divided into raid0 disk path “number of file stripes per file”, raid1 disk path “that is, the number of copies” of the former is the former. Integer multiples “indicate how many copies” were copied, and there are backup disks used to restore data. Here we still use multi-threading and use the idea of ​​​​raid0 and raid1 respectively. First divide the file into the number of raid0 disks and store them separately. Then copy the divided file strips one by one to On the raid1 disk, the file strips are stored in the same order as on the raid0 disk. When reading, the data on the raid0 disk is read out just like raid0. If it is damaged, it will be automatically read from the raid1 disk.
The idea when recovering files is to start from each disk – starting from the raid0 disk – first find the file objects that can complete the file strips of the original file and save them – if a certain piece of If the data cannot be found at all, the corresponding information will be output. After finding it, then go through all the disks to find the damaged disk – replace the damaged disk with the backup empty disk – and restore the data stored on the original disk to the new data disk.
Insert picture description here

4.7raid10

If you enter 7,, enter raid10. Raid10 copies files first and then partitions the files. However, when writing, I think this is not good compared to raid01 which partitions the tapes first and then copies the files. The efficiency is the lowest. So I think there is no point in writing this kind of program currently – so I still write it according to the idea of ​​raid01 – it’s just a difference in the disk array storage strategy. The paths of all data disks are stored in a two-dimensional dynamic array,The one-dimensional number represents the number of disks in raid0(The data is divided into several parts),The two-dimensional number represents the number of disks in raid1& #xff08;Copy several copies),When writing, first store the file strips divided according to the number of two-dimensional disks to the first one,of the two-dimensional disk, and then divide them The file strips can be copied to the disks in the same group. The reading and recovery ideas are basically the same as raid01 – I won’t go into details here.
Insert picture description here

5. Source code

https://gitee.com/zhuhezhang/raid
https://github.com/zhuhezhang/raid

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/use-java-simulation-to-implement-disk-array-raid-levels-0-1-3-5-6-01-10-2/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: 34331943@QQ.com

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索