|
.NET Framework | |||||||||
PREV TYPE NEXT TYPE | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONST | PROP | METHOD | OP | EVENT | DETAIL: FIELD | CONST | PROP | METHOD | OP | EVENT |
Manages the partial uncomplete download blocks
Field Summary | |
---|---|
System.Collections.ArrayList |
blocks
Blocks that have been finished and are stored |
long |
diskUsageKB
Total disk usage |
bool | gcDue |
bool | inited |
System.Collections.ArrayList |
inUseBlocks
Blocks that are currently being written too |
System.Threading.ReaderWriterLock | rwl |
Constructor Summary | |
---|---|
BlockStorage() Initializes a new instance of the BlockStorage class. |
Property Summary | |
---|---|
long |
DiskUsage
Gets the disk usage (in KB) of blocks |
bool |
GcDue
Gets whether a GC is due |
bool |
Oversize
Is storage oversize? |
double |
Utilisation
Gets utilisation of block storage |
string |
UtilStats
Gets a short string indicating utilisation details |
Method Summary | |
---|---|
Naanou.ResourceExchange.Block |
Create(long start, long end, long length, string contentHash) Creates a new block for a resource |
void |
DecrementDiskUsage(long amountKb) Decrements the disk usage counter |
void |
Delete(Naanou.ResourceExchange.Block block) Deletes a block from disk and internal db |
void |
Delete(Naanou.ResourceExchange.Block block, bool force) Deletes a block from memory and disk |
void |
DeleteFile(System.IO.FileInfo file) Deletes a file from disk |
void |
Gc(bool startupGc) Garbage collect block storage |
long |
GcDiskOrphans(Naanou.Common.PriorityQueue list, bool startupGc) Find blocks on disk that we don't know about. If startupGc is true, will also delete any incomplete blocks found |
void |
GcMemoryOrphans(bool startupGc) Remove all orphans in memory. |
void |
GcStale(Naanou.Common.PriorityQueue pq) Goes thru the sorted list {tick => block} and deletes blocks that are too old and incomplete |
void |
GcUnpopular() Sorts blocks by accessed frequency, and removes least accessed blocks first |
string |
GetBlockFilename(string contentHash, string range) Gets the absolute filename for a block |
void |
IncrementDiskUsage(long amountKb) Increments the disk usage counter |
void | Init() |
void |
Load() Loads block info from disk, forgetting current state. This is called on program startup |
void |
PromoteBlock(Naanou.ResourceExchange.Block block) Promotes a block from `in use' to idle. Do not call this method directly, use Naanou.ResourceExchange.Block.Retire. |
Naanou.ResourceExchange.Block[] |
Query(string contentHash) Find all complete blocks that are part of a certain file |
long | Query(string contentHash, System.Collections.ArrayList output, System.Collections.ArrayList source) |
Naanou.ResourceExchange.Block[] |
QueryAny(string contentHash) Finds all blocks complete or not |
void |
Save() Saves current block info to disk |
Methods inherited from class System.Object |
---|
Equals, Finalize, GetHashCode, GetType, MemberwiseClone, ToString |
Field Detail |
---|
private System.Collections.ArrayList blocks
Blocks that have been finished and are stored
private long diskUsageKB
Total disk usage
private bool gcDue
private bool inited
private System.Collections.ArrayList inUseBlocks
Blocks that are currently being written too
private System.Threading.ReaderWriterLock rwl
Constructor Detail |
---|
public BlockStorage()
Initializes a new instance of the BlockStorage class.
Property Detail |
---|
internal long DiskUsage
Gets the disk usage (in KB) of blocks
public bool GcDue
Gets whether a GC is due
internal bool Oversize
Is storage oversize?
internal double Utilisation
Gets utilisation of block storage
internal string UtilStats
Gets a short string indicating utilisation details
Method Detail |
---|
internal Naanou.ResourceExchange.Block Create(long start, long end, long length, string contentHash)
Creates a new block for a resource
Parameters:
contentHash
- Hash of contentsend
- Ending byte number (0-based)length
- Total length of resourcestart
- Starting byte number (0-based)private void DecrementDiskUsage(long amountKb)
Decrements the disk usage counter
Parameters:
amountKb
- Amount in kilobytes to decrement byinternal void Delete(Naanou.ResourceExchange.Block block)
Deletes a block from disk and internal db
Parameters:
block
- Block to deleteSystem.ArgumentException
- If block is marked Naanou.ResourceExchange.Block.RequiredLocallyinternal void Delete(Naanou.ResourceExchange.Block block, bool force)
Deletes a block from memory and disk
Parameters:
block
- Block to deleteforce
- If true, block will be removed even if block's RequiredLocally flag is setprivate void DeleteFile(System.IO.FileInfo file)
Deletes a file from disk
Parameters:
file
- public void Gc(bool startupGc)
Garbage collect block storage
Uses four methods to clean up on disk and memory usage. The fourth method is only performed when the first three fail to clean up enough space. Method - Description
private long GcDiskOrphans(Naanou.Common.PriorityQueue list, bool startupGc)
Find blocks on disk that we don't know about. If startupGc is true, will also delete any incomplete blocks found
Parameters:
list
- Returns a priority queue of blocks sorted in order of last writestartupGc
- Is Gc running due to a program startup?private void GcMemoryOrphans(bool startupGc)
Remove all orphans in memory.
private void GcStale(Naanou.Common.PriorityQueue pq)
Goes thru the sorted list {tick => block} and deletes blocks that are too old and incomplete
Parameters:
pq
- Priority queue in last write ticks orderprivate void GcUnpopular()
Sorts blocks by accessed frequency, and removes least accessed blocks first
private string GetBlockFilename(string contentHash, string range)
Gets the absolute filename for a block
Parameters:
contentHash
- Hashrange
- Rangeprivate void IncrementDiskUsage(long amountKb)
Increments the disk usage counter
Parameters:
amountKb
- Amount in kilobytes to increment byinternal void Init()
internal void Load()
Loads block info from disk, forgetting current state. This is called on program startup
internal void PromoteBlock(Naanou.ResourceExchange.Block block)
Promotes a block from `in use' to idle. Do not call this method directly, use Naanou.ResourceExchange.Block.Retire.
Parameters:
block
- internal Naanou.ResourceExchange.Block[] Query(string contentHash)
Find all complete blocks that are part of a certain file
Parameters:
contentHash
- Contents hashprivate long Query(string contentHash, System.Collections.ArrayList output, System.Collections.ArrayList source)
internal Naanou.ResourceExchange.Block[] QueryAny(string contentHash)
Finds all blocks complete or not
Parameters:
contentHash
- Hashinternal void Save()
Saves current block info to disk
|
.NET Framework | |||||||||
PREV TYPE NEXT TYPE | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONST | PROP | METHOD | OP | EVENT | DETAIL: FIELD | CONST | PROP | METHOD | OP | EVENT |