/** * Constructor. * * @param conf Configuration */ public DiskBackedPartitionStore(ImmutableClassesGiraphConfiguration<I, V, E, M> conf) { this.conf = conf; // We must be able to hold at least one partition in memory maxInMemoryPartitions = Math.max( 1, conf.getInt( GiraphConfiguration.MAX_PARTITIONS_IN_MEMORY, GiraphConfiguration.MAX_PARTITIONS_IN_MEMORY_DEFAULT)); basePath = conf.get("mapred.job.id", "Unknown Job") + conf.get( GiraphConfiguration.PARTITIONS_DIRECTORY, GiraphConfiguration.PARTITIONS_DIRECTORY_DEFAULT); }
/** * Read a partition from disk. * * @param partitionId Id of the partition to read * @return The partition object * @throws IOException */ private Partition<I, V, E, M> readPartition(Integer partitionId) throws IOException { Partition<I, V, E, M> partition = new Partition<I, V, E, M>(conf, partitionId); File file = new File(getPartitionPath(partitionId)); DataInputStream inputStream = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); int numVertices = onDiskPartitions.get(partitionId); for (int i = 0; i < numVertices; ++i) { Vertex<I, V, E, M> vertex = conf.createVertex(); vertex.readFields(inputStream); partition.putVertex(vertex); } inputStream.close(); file.delete(); return partition; }