Reduce directory depth by one.

Change-Id: I7f89df61135ff19169ed97633a662685d414c448
This commit is contained in:
Bjoern Rabenstein 2014-10-15 17:07:12 +02:00
parent 096fa0f8b2
commit 40354eaa29

View file

@ -37,8 +37,8 @@ const (
namespace = "prometheus" namespace = "prometheus"
subsystem = "persistence" subsystem = "persistence"
seriesFileName = "series.db" seriesFileSuffix = ".db"
seriesTempFileName = "series.db.tmp" seriesTempFileSuffix = ".db.tmp"
headsFileName = "heads.db" headsFileName = "heads.db"
headsFormatVersion = 1 headsFormatVersion = 1
@ -51,14 +51,14 @@ const (
chunkHeaderFirstTimeOffset = 1 chunkHeaderFirstTimeOffset = 1
chunkHeaderLastTimeOffset = 9 chunkHeaderLastTimeOffset = 9
// TODO: Consider making any of these configurable? // TODO: Consider making any of these configurable? At least tweak
// them. As of now, these are educated guesses.
indexingMaxBatchSize = 1024 * 1024 indexingMaxBatchSize = 1024 * 1024
indexingBatchTimeout = 500 * time.Millisecond // Commit batch when idle for that long. indexingBatchTimeout = 500 * time.Millisecond // Commit batch when idle for that long.
indexingQueueCapacity = 1024 indexingQueueCapacity = 1024
) )
const ( const (
_ = iota
flagChunkDescsLoaded byte = 1 << iota flagChunkDescsLoaded byte = 1 << iota
flagHeadChunkPersisted flagHeadChunkPersisted
) )
@ -568,8 +568,7 @@ func (p *persistence) dropChunks(fp clientmodel.Fingerprint, beforeTime clientmo
return false, err return false, err
} }
dirname := p.dirForFingerprint(fp) temp, err := os.OpenFile(p.tempFileNameForFingerprint(fp), os.O_WRONLY|os.O_CREATE, 0640)
temp, err := os.OpenFile(path.Join(dirname, seriesTempFileName), os.O_WRONLY|os.O_CREATE, 0640)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -579,7 +578,7 @@ func (p *persistence) dropChunks(fp clientmodel.Fingerprint, beforeTime clientmo
return false, err return false, err
} }
os.Rename(path.Join(dirname, seriesTempFileName), path.Join(dirname, seriesFileName)) os.Rename(p.tempFileNameForFingerprint(fp), p.fileNameForFingerprint(fp))
return false, nil return false, nil
} }
@ -746,28 +745,30 @@ func (p *persistence) close() error {
return lastError return lastError
} }
func (p *persistence) dirForFingerprint(fp clientmodel.Fingerprint) string { func (p *persistence) dirNameForFingerprint(fp clientmodel.Fingerprint) string {
fpStr := fp.String() fpStr := fp.String()
return fmt.Sprintf("%s/%c%c/%s", p.basePath, fpStr[0], fpStr[1], fpStr[2:]) return fmt.Sprintf("%s/%c%c", p.basePath, fpStr[0], fpStr[1])
}
func (p *persistence) fileNameForFingerprint(fp clientmodel.Fingerprint) string {
fpStr := fp.String()
return fmt.Sprintf("%s/%c%c/%s%s", p.basePath, fpStr[0], fpStr[1], fpStr[2:], seriesFileSuffix)
}
func (p *persistence) tempFileNameForFingerprint(fp clientmodel.Fingerprint) string {
fpStr := fp.String()
return fmt.Sprintf("%s/%c%c/%s%s", p.basePath, fpStr[0], fpStr[1], fpStr[2:], seriesTempFileSuffix)
} }
func (p *persistence) openChunkFileForWriting(fp clientmodel.Fingerprint) (*os.File, error) { func (p *persistence) openChunkFileForWriting(fp clientmodel.Fingerprint) (*os.File, error) {
dirname := p.dirForFingerprint(fp) if err := os.MkdirAll(p.dirNameForFingerprint(fp), 0700); err != nil {
ex, err := exists(dirname)
if err != nil {
return nil, err return nil, err
} }
if !ex { return os.OpenFile(p.fileNameForFingerprint(fp), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0640)
if err := os.MkdirAll(dirname, 0700); err != nil {
return nil, err
}
}
return os.OpenFile(path.Join(dirname, seriesFileName), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0640)
} }
func (p *persistence) openChunkFileForReading(fp clientmodel.Fingerprint) (*os.File, error) { func (p *persistence) openChunkFileForReading(fp clientmodel.Fingerprint) (*os.File, error) {
dirname := p.dirForFingerprint(fp) return os.Open(p.fileNameForFingerprint(fp))
return os.Open(path.Join(dirname, seriesFileName))
} }
func writeChunkHeader(w io.Writer, c chunk) error { func writeChunkHeader(w io.Writer, c chunk) error {