How edwardcapriolo/filecrush works
Purpose and execution model
FileCrush is a Hadoop MapReduce command-line utility that recursively converts many small DFS files into fewer bounded-size files, optionally changing text/SequenceFile formats and compression. Its operational entry point is src/main/java/com/m6d/filecrush/crush/Crush.java; cleanup is a separate command in src/main/java/com/m6d/filecrush/clean/Clean.java.
Job orchestration and planning
Crush.java parses global and ordered per-directory options, validates input/output behavior, and configures Hadoop jobs. Directory rules select input/output formats and output naming based on path regex/replacement. It establishes the boundary between CLI policy (threshold, clone mode, compression, block limits) and distributed execution.
• src/main/java/com/m6d/filecrush/crush/Crush.java
• src/main/java/com/m6d/filecrush/crush/Bucketer.java
Discovery and eligibility counting stage
A preliminary MapReduce stage inventories input files and captures file sizes, enabling files at or below the configured fraction of DFS block size to be crushed while “big enough” files are preserved/moved. Size-aware status handling and counter records support this planning phase.
• src/main/java/com/m6d/filecrush/crush/CountersInputFormat.java
• src/main/java/com/m6d/filecrush/crush/CountersMapper.java
• src/main/java/com/m6d/filecrush/crush/FileStatusHasSize.java
• src/main/java/com/m6d/filecrush/crush/MapperCounter.java
Bucketing and partitioning
Bucketer.java groups eligible small files by source directory and estimated output capacity, constrained by --max-file-blocks. This avoids a single oversized output and permits multiple reducers to process a large directory. CrushPartitioner.java routes bucketed work so records destined for the same generated output file are reduced together.
• src/main/java/com/m6d/filecrush/crush/Bucketer.java
• src/main/java/com/m6d/filecrush/crush/CrushPartitioner.java
Record read/write conversion boundary
The crushing reducer reads each selected source file through the configured Hadoop input format and writes records through the selected output format. Thus text and SequenceFile data can be copied or converted in one pass, with configured compression applied on write. KeyValuePreservingTextInputFormat protects text key/value semantics when delegating record reading.
• src/main/java/com/m6d/filecrush/crush/CrushReducer.java
• src/main/java/com/m6d/filecrush/crush/KeyValuePreservingTextInputFormat.java
• src/main/java/com/m6d/filecrush/crush/ReducerCounter.java
Output, clone, and file lifecycle
In standard mode, generated crushed files and untouched large files are placed under the requested output tree; crushable originals are removed from the input tree. In clone mode, generated files replace source files in place while originals are relocated under the clone output root, preserving their original hierarchy. Clean.java handles removal of job-created temporary DFS artifacts.
• src/main/java/com/m6d/filecrush/crush/Crush.java
• src/main/java/com/m6d/filecrush/clean/Clean.java
Runtime and infrastructure
The project is Java/Maven-based (pom.xml) and depends on Hadoop’s older org.apache.hadoop.mapred API, Hadoop DFS block sizing and filesystem operations, Hadoop InputFormat/OutputFormat implementations, and optional Hadoop compression codecs. It creates temporary working directories under the executing user’s DFS home tmp path.
Main entry points: Crush.java Crush command · CrushReducer.java Crush reducer · CountersMapper.java Eligibility mapper · CountersInputFormat.java Counters input format
Components 16
Commands
- Crush command · Parses policy and configures the Hadoop stages.
src/main/java/com/m6d/filecrush/crush/Crush.java - Clean command · Removes job-created temporary DFS artifacts.
src/main/java/com/m6d/filecrush/clean/Clean.java
Planning pipeline
- Directory rules · Select formats and output names by directory regex.
src/main/java/com/m6d/filecrush/crush/Crush.java - Counters input format · Inventories source file statuses for the eligibility stage.
src/main/java/com/m6d/filecrush/crush/CountersInputFormat.java - Eligibility mapper · Captures file sizes and eligibility counters.
src/main/java/com/m6d/filecrush/crush/CountersMapper.java - Sized file status · Carries file status with size-aware handling.
src/main/java/com/m6d/filecrush/crush/FileStatusHasSize.java - Mapper counter
src/main/java/com/m6d/filecrush/crush/MapperCounter.java - Bucketer · Groups eligible files by directory and bounded output capacity.
src/main/java/com/m6d/filecrush/crush/Bucketer.java
Distributed conversion
- Crush partitioner · Co-locates records for each generated output file.
src/main/java/com/m6d/filecrush/crush/CrushPartitioner.java - Crush reducer · Reads selected files and writes converted or copied records.
src/main/java/com/m6d/filecrush/crush/CrushReducer.java - KV-preserving text input · Preserves text key/value semantics during delegated reads.
src/main/java/com/m6d/filecrush/crush/KeyValuePreservingTextInputFormat.java - Reducer counter
src/main/java/com/m6d/filecrush/crush/ReducerCounter.java
DFS lifecycle
- Hadoop DFS · Provides filesystem operations, block sizing, formats, and codecs.
- Input tree · Small files are crushed; large files are preserved or moved.
- Output or clone tree · Contains crushed outputs and lifecycle-dependent originals.
- User tmp workspace · Created under the executing user's DFS home tmp path.
Connections 21
- Crush command → Directory rules: parses
- Crush command → Counters input format: launches inventory job
- Crush command → Bucketer: plans eligible files
- Crush command → Crush partitioner: configures crush job
- Crush command → Crush reducer: configures formats/compression
- Input tree → Counters input format: file inventory
- Counters input format → Eligibility mapper: file statuses
- Eligibility mapper → Sized file status: uses
- Eligibility mapper → Mapper counter: emits counters
- Eligibility mapper → Bucketer: size eligibility
- Bucketer → Crush partitioner: bucketed work
- Crush partitioner → Crush reducer: same output destination
- Input tree → Crush reducer: selected source files
- KV-preserving text input → Crush reducer: text record reads
- Crush reducer → Reducer counter: records results
- Crush reducer → Output or clone tree: writes crushed files
- Crush command → Input tree: removes or relocates originals
- Crush command → User tmp workspace: creates work area
- Clean command → User tmp workspace: removes
- Hadoop DFS → Input tree: hosts
- Hadoop DFS → Output or clone tree: hosts