{"id":26477856,"url":"https://github.com/adarsh-kmt/dragondb","last_synced_at":"2026-05-16T20:36:51.623Z","repository":{"id":282029196,"uuid":"932116647","full_name":"Adarsh-Kmt/DragonDB","owner":"Adarsh-Kmt","description":"A B+ Tree based database storage engine, written in Go.","archived":false,"fork":false,"pushed_at":"2026-03-24T10:45:27.000Z","size":6180,"stargazers_count":10,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-03-25T13:08:41.871Z","etag":null,"topics":["b-plus-tree","buffer-pool-manager","database","golang","slotted-page"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Adarsh-Kmt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-02-13T11:49:27.000Z","updated_at":"2026-03-24T10:45:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"83995950-b0ed-4e25-bff9-0f4f6f3772da","html_url":"https://github.com/Adarsh-Kmt/DragonDB","commit_stats":null,"previous_names":["adarsh-kmt/dragondb"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/Adarsh-Kmt/DragonDB","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adarsh-Kmt%2FDragonDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adarsh-Kmt%2FDragonDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adarsh-Kmt%2FDragonDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adarsh-Kmt%2FDragonDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Adarsh-Kmt","download_url":"https://codeload.github.com/Adarsh-Kmt/DragonDB/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adarsh-Kmt%2FDragonDB/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33118138,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T18:38:32.183Z","status":"ssl_error","status_checked_at":"2026-05-16T18:38:29.903Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["b-plus-tree","buffer-pool-manager","database","golang","slotted-page"],"created_at":"2025-03-20T00:53:29.255Z","updated_at":"2026-05-16T20:36:51.618Z","avatar_url":"https://github.com/Adarsh-Kmt.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/charizard_banner.jpg\" alt=\"banner\" width=\"400\"/\u003e\n\u003c/p\u003e\n\n\n# DragonDB\nA B+ Tree based database storage engine, written in Go.\n\nCheck out my [substack](https://adarshkmt.substack.com/s/building-a-database), where I'll be explaining how I built it, layer by layer.\n\n## Architecture\nCheckout [architecture.md](https://github.com/Adarsh-Kmt/DragonDB/blob/master/architecture.md) for an overview.\n\n## Installation and Setup\n\n### Prerequisites\n- Go 1.19 or higher\n- POSIX-compliant operating system (Linux, macOS)\n\n### Clone and Build\n```bash\ngit clone https://github.com/Adarsh-Kmt/DragonDB.git\ncd DragonDB\ngo mod tidy\ngo build ./...\n```\n\n## Technical Challenges Solved\n\n### 1. Race Condition in Root Node Initialization\n**Problem**: When multiple threads simultaneously try to insert into an empty B-tree, both detect that no root exists and attempt to create one, resulting in data loss.\n\n**Solution**: Implemented double-checked locking pattern:\n- Acquire read lock and check if root exists.\n- If not, release read lock and acquire write lock.\n- Re-check condition under write lock to make sure another thread didn't initialize a root node before write lock could be acquired.\n- Only one thread successfully initializes the root.\n\n### 2. Duplicate Page Fetching\n**Problem**: When multiple threads simultaneously try to read the same page from disk, duplicate copies of the page are created in memory.\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/Race Conditions/Fetch Page/1. Race Condition.png\" alt=\"Architecture Diagram\" width=\"1000\"/\u003e\n\u003c/p\u003e\n\n**Solution**: Implemented double-checked locking pattern:\n- Acquire read lock and check if page exists in memory.\n- If not, release read lock and acquire write lock.\n- Re-check condition under write lock to make sure another thread didn't make a copy of the page before write lock could be acquired.\n- Only one thread successfully initializes the root.\n\n  \u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/Race Conditions/Fetch Page/3. Read-Write Lock Solution.png\" alt=\"Architecture Diagram\" width=\"1000\"/\u003e\n\u003c/p\u003e\n\n### 3. Resource Leaks in Error Paths\n**Problem**: Page allocation followed by I/O error left allocated page unused, causing memory leaks.\n\n**Solution**: Comprehensive cleanup patterns:\n- Immediate cleanup on I/O failure.\n\n### 4. Direct I/O Performance Optimization\n**Problem**: Buffered I/O operations suffered from double-buffering and unpredictable kernel cache behavior.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/Buffered IO/Buffered IO.png\" alt=\"Architecture Diagram\" width=\"1000\"/\u003e\n\u003c/p\u003e\n\n**Solution**: Custom Direct I/O implementation:\n- Data from disk is transferred directly to user space memory using Direct I/O, bypassing the kernel page cache.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/Direct IO/Direct IO.png\" alt=\"Architecture Diagram\" width=\"1000\"/\u003e\n\u003c/p\u003e\n\n## License:\n\n```\nMIT License\n\nCopyright (c) 2024 Adarsh Kamath\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadarsh-kmt%2Fdragondb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadarsh-kmt%2Fdragondb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadarsh-kmt%2Fdragondb/lists"}