Are you looking at v20 or v23?  Note that 
HDFS-1070<https://issues.apache.org/jira/browse/HDFS-1070> changed the format.

But I would describe both the old and the new format as "breadth-first within 
each directory, depth-first between directories", because when a directory is 
serialized, all its immediate children (file and directory inodes) are listed 
together, but the ordering of directories is depth-first.

As for the ordering of children within each directory, as you observed,
-  FSImage.saveImage() uses the "for (INode child : current.getChildren())" 
iterator to traverse the list of children; and
-  INodeDirectory.addChild() uses an ArrayList and binary search and add(index) 
to keep the list of children in alphabetical order.

--Matt


On May 2, 2011, at 6:39 PM, Thanh Do wrote:

Thanks Todd,

I looked at FSImage.saveImage().
It turns out the order is depth first.

I saw this loop:
for (INode child : current.getChildren()) {
   ...
   saveInode2Image(..)
}

So the order of saving is based on how child list
is organized. According from the code from
INodeDirectory.addChild(), every time we add a child,
we do a binary search to find the appropriate insert location.

So I think the child list is sorted on alphabetical order.
Am I right?

Thanh

On Mon, May 2, 2011 at 3:51 PM, Todd Lipcon 
<t...@cloudera.com<mailto:t...@cloudera.com>> wrote:
On Mon, May 2, 2011 at 1:20 PM, Thanh Do 
<than...@cs.wisc.edu<mailto:than...@cs.wisc.edu>> wrote:
hi all,

perhaps this is a dummy question but
can anyone tell me that when
the namenode saves a fsimage,
are the Inodes saved in an alphabetical order?

Hi Thanh,

They're saved in directory traversal order (can't remember if it's breadth 
first or depth first, but the code should tell you)

-Todd
--
Todd Lipcon
Software Engineer, Cloudera


Reply via email to