* First, attempt to delete the path, if the path is big (i.e. exceeds writeSizeLimit of tiny), * it will perform multi-path recursive chunked deletes in rounds. * Each round, it fetches listNumSubPath subPaths and issue batches based on batchSize. * At the end of each round, it adjustes the
(path: string)
| 63 | * @return true if this path is small (Does not exceed writeSizeLimit of tiny) |
| 64 | */ |
| 65 | private async deletePath(path: string): Promise<boolean> { |
| 66 | if (await this.deleteJobStack.run(() => this.remote.deletePath(path))) { |
| 67 | return true; |
| 68 | } |
| 69 | let listNumSubPath = INITIAL_LIST_NUM_SUB_PATH; |
| 70 | // The range of batchSize to gradually narrow down. |
| 71 | let batchSizeLow = 1; |
| 72 | let batchSizeHigh = MAX_LIST_NUM_SUB_PATH + 1; |
| 73 | let batchSize = INITIAL_DELETE_BATCH_SIZE; |
| 74 | while (true) { |
| 75 | const subPathList = await this.listStack.run(() => |
| 76 | this.listRemote.listPath(path, listNumSubPath), |
| 77 | ); |
| 78 | if (subPathList.length === 0) { |
| 79 | return false; |
| 80 | } |
| 81 | const chunks = chunkList(subPathList, batchSize); |
| 82 | let nSmallChunks = 0; |
| 83 | for (const chunk of chunks) { |
| 84 | if (await this.deleteSubPath(path, chunk)) { |
| 85 | nSmallChunks += 1; |
| 86 | } |
| 87 | } |
| 88 | // Narrow the batchSize range depending on whether the majority of the chunks are small. |
| 89 | if (nSmallChunks > chunks.length / 2) { |
| 90 | batchSizeLow = batchSize; |
| 91 | batchSize = Math.floor(Math.min(batchSize * 2, (batchSizeHigh + batchSize) / 2)); |
| 92 | } else { |
| 93 | batchSizeHigh = batchSize; |
| 94 | batchSize = Math.floor((batchSizeLow + batchSize) / 2); |
| 95 | } |
| 96 | // Start with small number of sub paths to learn about an appropriate batchSize. |
| 97 | if (listNumSubPath * 2 <= MAX_LIST_NUM_SUB_PATH) { |
| 98 | listNumSubPath = listNumSubPath * 2; |
| 99 | } else { |
| 100 | listNumSubPath = Math.floor(MAX_LIST_NUM_SUB_PATH / batchSize) * batchSize; |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * Similar to deletePath, but delete multiple subpaths at once. |
no test coverage detected