y****3 发帖数: 131 | 1 【 以下文字转载自 Database 讨论区 】
发信人: yh1213 (yh), 信区: Database
标 题: An interview question: data store schema design
发信站: BBS 未名空间站 (Sat Mar 24 18:30:54 2012, 美东)
Design a backend store for storing metadata about files and directories
belonging to different users as part of an online storage service. The
logical data model is as follows:
--a user has zero or more files or directories
--a directory contains zero or more files or sub-directories
--a file or directory has a relative path that is up to 32KB in length
--a file has a size and last modified time
This store should handle the following online queries efficiently:
--lookups on single files or sub-directory given a user and relative path
--listing all files and sub-directories belonging to a user or at a given
level of the hierarchy inserting new files and directories
It should also support the following batch operations that run on a daily
basis:
--count the total number of files per user, and the aggregate file size.
--count the number of files and sub-directories added per day for each user.
I can think of creating such a schema:
1. User table (userName, userId, etc)
2. File table (userId, file/dirName, relativePath, size, lastModified,
isFile) whereas as key, and is a foreign key
to User table.
Not sure if this the right answer. Also, if the data grow to say, billions
of rows, would sharding a good enough solution? |
|