DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • What Is Quick Sort in C Programming?
  • TypeScript: Useful Features
  • Training a Handwritten Digits Classifier in Pytorch With Apache Cassandra Database
  • Build a Digital Collectibles Portal Using Flow and Cadence (Part 1)

Trending

  • Best Plugins For JetBrains IDEs
  • Deploy a Session Recording Solution Using Ansible and Audit Your Bastion Host
  • Effective Tips for Debugging Complex Code in Java
  • 5 Web3 Trends to Follow in 2023
  1. DZone
  2. Data Engineering
  3. Data
  4. How Saving a Single Byte Cost Me Over a Day (and Was Solved With a Single Byte)

How Saving a Single Byte Cost Me Over a Day (and Was Solved With a Single Byte)

An example of a simple error, a simple solution, and a single byte.

Oren Eini user avatar by
Oren Eini
·
Oct. 27, 15 · Opinion
Like (3)
Save
Tweet
Share
5.48K Views

Join the DZone community and get the full member experience.

Join For Free

i’m currently doing something that i would rather not do. i’m doing significant refactoring to the lowest level of ravendb, preparing some functionality that i need to develop some visible features. but in the meantime, i’m mucking about in the storage layer, dealing with how voron actually persists and manages the information we have. and i’m making drastic changes. that means that stuff breaks, but we have got the tests to cover for us, so we are good in that regard - yeah!

the case for this post is that i decided to break apart a class that had too many responsibilities. the class in question was:

image

as you can see, there are multiple concerns here. there are actually several types of page in the system, but changing this would have been a major change so i just tucked more responsibility into this poor class at the time.

when i finally got around to actually handling this it was part of a much larger body of work, but i felt really great that i was able to do that.

that was until i ran the tests, and a few of them broke. in particular, only the tests that deal with large amounts of information (over four million entries) broke. and they broke in a really annoying way - it looked like utter memory corruption was happening. it was scary, and it took me a long while to figure out what was going on.

here is the fix:

image

this error happens when adding a new entry to a tree. in particular, this piece of code will only run when we have a page split on a branch page (that is, we need to move from two levels in the tree to three levels).

the issue turned out to be because when we split the fixed size tree from the variable size tree, i was able to save a single byte in the header of the fixed size tree page. the previous header was 17 bytes in size, and the new header was 16 bytes in size.

the size of branchentrysize is 16 bytes… and i think you get the error now, right?

before, with page size of 4k, we had a pagemaxsize of 4079 bytes. so on the 255 entry, we would be over the limit, and split the page. by reducing a single byte from the header, the pagemaxsize was 4080. because we only checked from greater than, we thought that we could write to that page; but we ended up writing to the next page, corrupting it.

the fix, ironically enough, was to add another byte, to check for greater than or equal.

smile

Data Types

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • What Is Quick Sort in C Programming?
  • TypeScript: Useful Features
  • Training a Handwritten Digits Classifier in Pytorch With Apache Cassandra Database
  • Build a Digital Collectibles Portal Using Flow and Cadence (Part 1)

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: