I am trying to understand how one designs an object graph such that related objects will be placed in the correct shard.
I looked through the test code that came with Shards and am confused as to how objects get distributed.
Simplifying the object graph a lot, lets assume buildings have floors, floors have offices, and offices have furniture reflected in the following objects:
public class Building {
private Serializable buildingId;
private String name;
private List<Floor> floors = Lists.newArrayList();
}
public class Floor {
private Serializable floorId;
private int number;
private BigDecimal squareFeet;
private List<Office> offices = Lists.newArrayList();
}
public class Office {
private Serializable officeId;
private String label;
private Floor floor;
private List<Furniture> furniture = Lists.newArrayList();
}
public class Furniture {
private Serializable furnitureId;
private String description;
private Office office;
}
I also know that I might try to look up office id: XYZ in build 123 however I know I will never want to be able to look up a piece of furniture directly, I would only want to find out what furniture is in a given office.
Since everything is a child or descendant of a building I assume I want to shard based on building ID. If this is true are the following statements true?:
a) The ID of the floor and office would have to have the Buildings ID in it or at least have enough info in the ID to determine what the shard id of the building the floor and office belonged to? What about furniture?
b) I would need to write a ShardSelectionStrategy such that if the object passed in was a Building, it would assign it a shard (perhaps based on the modulo of the number of shards and building id?) and if something was a floor, office, or furniture, it would navigate the object map back to get the building ID and assign the object to the appropriate shard for the building they belong to.
c) In order for the ShardResolutionStrategy to not have to query every shard looking for an office or floor I assume I would have to make the building part of the compound key for the furniture, office, and floor? It would then do the mod operation on the building ID and determine what shard they lived in?
d) I assume if I wanted to get the list of 10 largest floors in a given building ordered by square feet I would get the ShardedSession for the shard that the building lived in and would then execute the Criteria as though it were standard hibernate since I know all the relevant floors are in that shard?
I guess my main question is, if I have an object graph that consists of a bunch of unique trees, how do I make sure all the items for a given tree are in one shard and then how is it recommended I determine which tree goes in which shard?
Are there any more elaborate examples than the documentation on the hibernate site and the google podcast?
Thanks,
Eric
|