Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

K4 v1.9.6

Choose a tag to compare

@guycipher guycipher released this 05 Nov 20:32
· 90 commits to main since this release

K4 v1.9.6 PATCH

  • Update to pager which is used for WAL, and SSTables to periodically sync to disk.

New pager constants

const SYNC_TICK_INTERVAL = 1 * time.Second // tick interval for syncing the file
const SYNC_ESCALATION = 1 * time.Minute    // if the file is not synced in 1 minute, sync it
const WRITE_THRESHOLD = 24576              // every 24576 writes, sync the file

New periodic sync method

func (p *Pager) startPeriodicSync() {
	defer p.wg.Done()

	p.once.Do(func() {

		ticker := time.NewTicker(SYNC_TICK_INTERVAL)
		defer ticker.Stop()
		for {
			select {
			case <-ticker.C:
				if p.writeCounter < WRITE_THRESHOLD {
					if time.Since(p.lastSync) < SYNC_ESCALATION { // check if the file is synced in SYNC_ESCALATION
						continue
					} // if the file is not synced in SYNC_ESCALATION, sync it

				}
				err := p.file.Sync()
				if err != nil {
					return
				}
				p.lock.Lock()
				p.writeCounter = 0
				p.lastSync = time.Now()
				p.lock.Unlock()
			case <-p.stopSync:
				return
			}
		}
	})
}

2bc1ab4

Reddit discussion
https://www.reddit.com/r/databasedevelopment/comments/1gk18nd/comment/lvkomdj/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button