chkpt

package
v0.0.0-...-92f3312 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2020 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Overview

The chkpt package implements a checkpoint file manager. The checkpoint scheme is based on a two tumbler (a and b) system where the b tumber cyles with each call, and the a tumber cycles once with each roll-over of b. If the roll point of b is 24 and the roll point of a is three, checkpoint files are created in this order:

a1, b1, b2, b3... b24, a2, b1... b24, a2...

If the using programme is creating a checkpoint every hour, then an 'a' file is created once per day with a coverage of three days; at the end of the third cycle there will exist a1 (2 days old), a2 (one day old) and a3 new, along with 24 'b' files.

As the checkpoint is written, the mdd5sum is computed and if desired upon close the value is added to the name such that final names have the form:

<path>_Xnn-<md5>.ckpt

This is enabled by invoking the Add_md5() function after the checkpoint object is created.

The file <path>.ckpt (no tumbler) is used to record the tumbler values such that the next time the programme is started it will create the next file in a continued sequence rather than resetting or requiring the user programme to manage the tumbler data.

chkpt implements the io.Writer interface such that it is possible to use the pointer to the object in an fmt.Fprintf() call:

c = Mk_chkpt( "/usr2/ckpts/agama", 5, 25 )
c.Create()
fmt.Fprintf( c, "%s\n", data )
c.Close()

The method Write_string( string ) can also be used to write to an open checkpoint file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chkpt

type Chkpt struct {
	// contains filtered or unexported fields
}

Defines a checkpoint environment.

func Mk_chkpt

func Mk_chkpt(path string, amax int, bmax int) (c *Chkpt)

Mk_chkpt creates a checkpointing environment. Path is any leading directory path, with a basename (prefix) mask (e.g. /usr2/backups/foo). The tumbler information is added to path in the form of either a_xxxx or b_xxxx where xxx is the tumbler number.

func (*Chkpt) Add_md5

func (c *Chkpt) Add_md5()

Sets the flag that will cause the final file name to include the MD5 value computed for the file. Adding the md5 breaks the 'overlay' nature of the tumbler system.

func (*Chkpt) Close

func (c *Chkpt) Close() (final_name string, err error)

Closes the open checkpoint file. The final file is renamed with the md5sum (if no write errors). The final filename and any error status are reported to the caller. Success is reported (err == nil) only when no write errors and a successful close/rename.

func (*Chkpt) Create

func (c *Chkpt) Create() error

The create method caues a new checkpoint file to be created and opened. Once opened, thw Write or Write_string methods can be called to write to the the file. The Close method should be invoked when all writing has occurred.

func (*Chkpt) Write

func (c *Chkpt) Write(b []byte) (n int, err error)

Write allows the Go fmt package to be used to easily write a formatted string to the open checkpoint file. (see the example in the package description for how the fmt package can be used.

func (*Chkpt) Write_string

func (c *Chkpt) Write_string(s string) (n int, err error)

Write_string writes the string to the open chkpt file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL