func openTable(path string, retentionMonths int, getDeletedMetricIDs func() map[uint64]struct{}) (*table, error) {
	path = filepath.Clean(path)

	// Create a directory for the table if it doesn't exist yet.
	if err := fs.MkdirAllIfNotExist(path); err != nil {
		return nil, fmt.Errorf("cannot create directory for table %q: %s", path, err)
	}

	flockFile := path + "/flock.lock"
	flockF, err := os.Create(flockFile)
	if err != nil {
		return nil, fmt.Errorf("cannot create lock file %q: %s", flockFile, err)
	}
	if err := unix.Flock(int(flockF.Fd()), unix.LOCK_EX|unix.LOCK_NB); err != nil {
		return nil, fmt.Errorf("cannot acquire lock on file %q: %s", flockFile, err)
	}

	// Create directories for small and big partitions if they don't exist yet.
	smallPartitionsPath := path + "/small"
	if err := fs.MkdirAllIfNotExist(smallPartitionsPath); err != nil {
		return nil, fmt.Errorf("cannot create directory for small partitions %q: %s", smallPartitionsPath, err)
	}
	smallSnapshotsPath := smallPartitionsPath + "/snapshots"
	if err := fs.MkdirAllIfNotExist(smallSnapshotsPath); err != nil {
		return nil, fmt.Errorf("cannot create %q: %s", smallSnapshotsPath, err)
	}
	bigPartitionsPath := path + "/big"
	if err := fs.MkdirAllIfNotExist(bigPartitionsPath); err != nil {
		return nil, fmt.Errorf("cannot create directory for big partitions %q: %s", bigPartitionsPath, err)
	}
	bigSnapshotsPath := bigPartitionsPath + "/snapshots"
	if err := fs.MkdirAllIfNotExist(bigSnapshotsPath); err != nil {
		return nil, fmt.Errorf("cannot create %q: %s", bigSnapshotsPath, err)
	}

	// Open partitions.
	pts, err := openPartitions(smallPartitionsPath, bigPartitionsPath, getDeletedMetricIDs)
	if err != nil {
		return nil, fmt.Errorf("cannot open partitions in the table %q: %s", path, err)
	}

	tb := &table{
		path:                path,
		smallPartitionsPath: smallPartitionsPath,
		bigPartitionsPath:   bigPartitionsPath,
		getDeletedMetricIDs: getDeletedMetricIDs,

		flockF: flockF,

		stop: make(chan struct{}),
	}
	for _, pt := range pts {
		tb.addPartitionNolock(pt)
	}
	if retentionMonths <= 0 || retentionMonths > maxRetentionMonths {
		retentionMonths = maxRetentionMonths
	}
	tb.retentionMilliseconds = int64(retentionMonths) * 31 * 24 * 3600 * 1e3

	tb.startRetentionWatcher()
	return tb, nil
}
// openTable opens a table on the given path with the given retentionMonths.
//
// The table is created if it doesn't exist.
//
// Data older than the retentionMonths may be dropped at any time.
openTable opens a table on the given path with the given retentionMonths.

The table is created if it doesn't exist.

Data older than the retentionMonths may be dropped at any time.
// openTable opens a table on the given path with the given retentionMonths . // // The table is created if it doesn ' t exist . // // Data older than the retentionMonths may be dropped at any time .
func openTable(path string, retentionMonths int, getDeletedMetricIDs func() map[uint64]struct{}) (*table, error) {
	path = filepath.Clean(path)
	if err := fs.MkdirAllIfNotExist(path); err != nil {
		return nil, fmt.Errorf("cannot create directory for table %q: %s", path, err)
	}
	flockFile := path + "/flock.lock"
	flockF, err := os.Create(flockFile)
	if err != nil {
		return nil, fmt.Errorf("cannot create lock file %q: %s", flockFile, err)
	}
	if err := unix.Flock(int(flockF.Fd()), unix.LOCK_EX|unix.LOCK_NB); err != nil {
		return nil, fmt.Errorf("cannot acquire lock on file %q: %s", flockFile, err)
	}
	smallPartitionsPath := path + "/small"
	if err := fs.MkdirAllIfNotExist(smallPartitionsPath); err != nil {
		return nil, fmt.Errorf("cannot create directory for small partitions %q: %s", smallPartitionsPath, err)
	}
	smallSnapshotsPath := smallPartitionsPath + "/snapshots"
	if err := fs.MkdirAllIfNotExist(smallSnapshotsPath); err != nil {
		return nil, fmt.Errorf("cannot create %q: %s", smallSnapshotsPath, err)
	}
	bigPartitionsPath := path + "/big"
	if err := fs.MkdirAllIfNotExist(bigPartitionsPath); err != nil {
		return nil, fmt.Errorf("cannot create directory for big partitions %q: %s", bigPartitionsPath, err)
	}
	bigSnapshotsPath := bigPartitionsPath + "/snapshots"
	if err := fs.MkdirAllIfNotExist(bigSnapshotsPath); err != nil {
		return nil, fmt.Errorf("cannot create %q: %s", bigSnapshotsPath, err)
	}
	pts, err := openPartitions(smallPartitionsPath, bigPartitionsPath, getDeletedMetricIDs)
	if err != nil {
		return nil, fmt.Errorf("cannot open partitions in the table %q: %s", path, err)
	}
	tb := &table{
		path:                path,
		smallPartitionsPath: smallPartitionsPath,
		bigPartitionsPath:   bigPartitionsPath,
		getDeletedMetricIDs: getDeletedMetricIDs,
		flockF: flockF,
		stop: make(chan struct{}),
	}
	for _, pt := range pts {
		tb.addPartitionNolock(pt)
	}
	if retentionMonths <= 0 || retentionMonths > maxRetentionMonths {
		retentionMonths = maxRetentionMonths
	}
	tb.retentionMilliseconds = int64(retentionMonths) * 31 * 24 * 3600 * 1e3
	tb.startRetentionWatcher()
	return tb, nil
}
func openTable ( path string , retentionMonths int , getDeletedMetricIDs func ( ) map [ uint64 ] struct { } ) ( * table , error ) { path = filepath . Clean ( path ) if err := fs . MkdirAllIfNotExist ( path ) ; err != nil { return nil , fmt . Errorf ( " " , path , err ) } flockFile := path + " " flockF , err := os . Create ( flockFile ) if err != nil { return nil , fmt . Errorf ( " " , flockFile , err ) } if err := unix . Flock ( int ( flockF . Fd ( ) ) , unix . LOCK_EX | unix . LOCK_NB ) ; err != nil { return nil , fmt . Errorf ( " " , flockFile , err ) } smallPartitionsPath := path + " " if err := fs . MkdirAllIfNotExist ( smallPartitionsPath ) ; err != nil { return nil , fmt . Errorf ( " " , smallPartitionsPath , err ) } smallSnapshotsPath := smallPartitionsPath + " " if err := fs . MkdirAllIfNotExist ( smallSnapshotsPath ) ; err != nil { return nil , fmt . Errorf ( " " , smallSnapshotsPath , err ) } bigPartitionsPath := path + " " if err := fs . MkdirAllIfNotExist ( bigPartitionsPath ) ; err != nil { return nil , fmt . Errorf ( " " , bigPartitionsPath , err ) } bigSnapshotsPath := bigPartitionsPath + " " if err := fs . MkdirAllIfNotExist ( bigSnapshotsPath ) ; err != nil { return nil , fmt . Errorf ( " " , bigSnapshotsPath , err ) } pts , err := openPartitions ( smallPartitionsPath , bigPartitionsPath , getDeletedMetricIDs ) if err != nil { return nil , fmt . Errorf ( " " , path , err ) } tb := & table { path : path , smallPartitionsPath : smallPartitionsPath , bigPartitionsPath : bigPartitionsPath , getDeletedMetricIDs : getDeletedMetricIDs , flockF : flockF , stop : make ( chan struct { } ) , } for _ , pt := range pts { tb . addPartitionNolock ( pt ) } if retentionMonths <= 0 || retentionMonths > maxRetentionMonths { retentionMonths = maxRetentionMonths } tb . retentionMilliseconds = int64 ( retentionMonths ) * 31 * 24 * 3600 * 1e3 tb . startRetentionWatcher ( ) return tb , nil }
openTable opens a table on the given path with the given retentionMonths.
openTable opens a table on the given path with the given retentionMonths .
// Create a directory for the table if it doesn't exist yet. // Create directories for small and big partitions if they don't exist yet. // Open partitions.