Skip to content

Commit

Permalink
merge 'main' into 'feat/variable-block-size'
Browse files Browse the repository at this point in the history
Signed-off-by: Mingzhuo Yin <[email protected]>
  • Loading branch information
silver-ymz committed Jan 7, 2025
2 parents 7e92b62 + 52cbdfb commit ac59bf8
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 717 deletions.
664 changes: 13 additions & 651 deletions LICENSE

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,11 @@ CREATE EXTENSION vchord_bm25;
- `bm25_catalog.segment_growing_max_page_size (integer)`: The maximum page count of the growing segment. When the size of the growing segment exceeds this value, the segment will be sealed into a read-only segment. Default is 1, minimum is 1, and maximum is 1,000,000.

## License
This project is licensed under the [GNU Affero General Public License v3.0](./LICENSE) and as commercial software. For commercial licensing, please contact us at [email protected].

This software is licensed under a dual license model:

1. **GNU Affero General Public License v3 (AGPLv3)**: You may use, modify, and distribute this software under the terms of the AGPLv3.

2. **Elastic License v2 (ELv2)**: You may also use, modify, and distribute this software under the Elastic License v2, which has specific restrictions.

You may choose either license based on your needs. We welcome any commercial collaboration or support, so please email us <[email protected]> with any questions or requests regarding the licenses.
23 changes: 23 additions & 0 deletions licenses/LICENSE.AGPLv3
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Dual License Notice

This software is licensed under a dual license model. You may choose to use this software under one of the following licenses:

1. **GNU Affero General Public License v3 (AGPLv3)**

This program is free software: you can redistribute it and/or modify it under the terms of the AGPLv3.
You should have received a copy of the AGPLv3 along with this program. If not, see <https://www.gnu.org/licenses/agpl-3.0.html>.

The AGPLv3 license allows you to use, modify, and distribute the software, but requires you to share your modifications under the same license.

2. **Elastic License v2 (ELv2)**

This software is also licensed under the Elastic License v2.
For details, see <https://www.elastic.co/licensing/elastic-license>.

The Elastic License v2 allows you to use, modify, and distribute the software, but imposes certain restrictions, particularly regarding the provision of the software as a service.

## Choosing a License

You may choose to use this software under either the AGPLv3 or the Elastic License v2. If you choose the AGPLv3, you must comply with its terms. If you choose the Elastic License v2, you must comply with its terms.

By using this software, you agree to adhere to the terms of the license you select.
91 changes: 91 additions & 0 deletions licenses/LICENSE.ELv2
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
Elastic License 2.0

## Acceptance

By using the software, you agree to all of the terms and conditions below.

## Copyright License

The licensor grants you a non-exclusive, royalty-free, worldwide,
non-sublicensable, non-transferable license to use, copy, distribute, make
available, and prepare derivative works of the software, in each case subject to
the limitations and conditions below.

## Limitations

You may not provide the software to third parties as a hosted or managed
service, where the service provides users with access to any substantial set of
the features or functionality of the software.

You may not move, change, disable, or circumvent the license key functionality
in the software, and you may not remove or obscure any functionality in the
software that is protected by the license key.

You may not alter, remove, or obscure any licensing, copyright, or other notices
of the licensor in the software. Any use of the licensor’s trademarks is subject
to applicable law.

## Patents

The licensor grants you a license, under any patent claims the licensor can
license, or becomes able to license, to make, have made, use, sell, offer for
sale, import and have imported the software, in each case subject to the
limitations and conditions in this license. This license does not cover any
patent claims that you cause to be infringed by modifications or additions to
the software. If you or your company make any written claim that the software
infringes or contributes to infringement of any patent, your patent license for
the software granted under these terms ends immediately. If your company makes
such a claim, your patent license ends immediately for work on behalf of your
company.

## Notices

You must ensure that anyone who gets a copy of any part of the software from you
also gets a copy of these terms.

If you modify the software, you must include in any modified copies of the
software prominent notices stating that you have modified the software.

## No Other Rights

These terms do not imply any licenses other than those expressly granted in
these terms.

## Termination

If you use the software in violation of these terms, such use is not licensed,
and your licenses will automatically terminate. If the licensor provides you
with a notice of your violation, and you cease all violation of this license no
later than 30 days after you receive that notice, your licenses will be
reinstated retroactively. However, if you violate these terms after such
reinstatement, any additional violation of these terms will cause your licenses
to terminate automatically and permanently.

## No Liability

*As far as the law allows, the software comes as is, without any warranty or
condition, and the licensor will not be liable to you for any damages arising
out of these terms or the use or nature of the software, under any kind of
legal claim.*

## Definitions

The **licensor** is the entity offering these terms, and the **software** is the
software the licensor makes available under these terms, including any portion
of it.

**you** refers to the individual or entity agreeing to these terms.

**your company** is any legal entity, sole proprietorship, or other kind of
organization that you work for, plus all organizations that have control over,
are under the control of, or are under common control with that
organization. **control** means ownership of substantially all the assets of an
entity, or the power to direct its management and policies by vote, contract, or
otherwise. Control can be direct or indirect.

**your licenses** are all the licenses granted to you for the software under
these terms.

**use** means anything you do with the software requiring one of your licenses.

**trademark** means trademarks, service marks, and similar rights.
35 changes: 22 additions & 13 deletions src/page/virtual.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
bm25_page_size, page_alloc_init_forknum, page_alloc_with_fsm, page_read, page_write, PageFlags,
PageReadGuard, PageWriteGuard,
PageWriteGuard,
};

const DIRECT_COUNT: usize = bm25_page_size() / 4;
Expand All @@ -9,14 +9,24 @@ const INDIRECT2_COUNT: usize = INDIRECT1_COUNT * DIRECT_COUNT;

pub struct VirtualPageReader {
relation: pgrx::pg_sys::Relation,
direct_inode: PageReadGuard,
direct_inode: Box<[u32]>,
indirect1_inode_blkno: u32,
}

impl VirtualPageReader {
pub fn new(relation: pgrx::pg_sys::Relation, blkno: u32) -> Self {
assert!(blkno != pgrx::pg_sys::InvalidBlockNumber);
let direct_inode_page = page_read(relation, blkno);
let data = direct_inode_page.data();
let mut direct_inode: Vec<u32> = Vec::with_capacity(data.len() / 4);
direct_inode.extend_from_slice(bytemuck::cast_slice(data));
let direct_inode = direct_inode.into_boxed_slice();
let indirect1_inode_blkno = direct_inode_page.opaque.next_blkno;

Self {
relation,
direct_inode: page_read(relation, blkno),
direct_inode,
indirect1_inode_blkno,
}
}

Expand All @@ -43,19 +53,18 @@ impl VirtualPageReader {
pub fn get_block_id(&self, virtual_id: u32) -> u32 {
let mut virtual_id = virtual_id as usize;
if virtual_id < DIRECT_COUNT {
let slice = &self.direct_inode.content[virtual_id * 4..][..4];
return u32::from_le_bytes(slice.try_into().unwrap());
return self.direct_inode[virtual_id];
}

virtual_id -= DIRECT_COUNT;
let indirect1_inode = page_read(self.relation, self.direct_inode.opaque.next_blkno);
let indirect1_inode = page_read(self.relation, self.indirect1_inode_blkno);
if virtual_id < INDIRECT1_COUNT {
let indirect1_id = virtual_id / DIRECT_COUNT;
let indirect1_offset = virtual_id % DIRECT_COUNT;
let slice = &indirect1_inode.content[indirect1_id * 4..][..4];
let slice = &indirect1_inode.data()[indirect1_id * 4..][..4];
let blkno = u32::from_le_bytes(slice.try_into().unwrap());
let indirect = page_read(self.relation, blkno);
let slice = &indirect.content[indirect1_offset * 4..][..4];
let slice = &indirect.data()[indirect1_offset * 4..][..4];
return u32::from_le_bytes(slice.try_into().unwrap());
}

Expand All @@ -66,13 +75,13 @@ impl VirtualPageReader {
let indirect2_offset = virtual_id % INDIRECT1_COUNT;
let indirect1_id = indirect2_offset / DIRECT_COUNT;
let indirect1_offset = indirect2_offset % DIRECT_COUNT;
let slice = &indirect2_inode.content[indirect2_id * 4..][..4];
let slice = &indirect2_inode.data()[indirect2_id * 4..][..4];
let blkno = u32::from_le_bytes(slice.try_into().unwrap());
let indirect1 = page_read(self.relation, blkno);
let slice = &indirect1.content[indirect1_id * 4..][..4];
let slice = &indirect1.data()[indirect1_id * 4..][..4];
let blkno = u32::from_le_bytes(slice.try_into().unwrap());
let indirect = page_read(self.relation, blkno);
let slice = &indirect.content[indirect1_offset * 4..][..4];
let slice = &indirect.data()[indirect1_offset * 4..][..4];
u32::from_le_bytes(slice.try_into().unwrap())
}
}
Expand Down Expand Up @@ -277,7 +286,7 @@ impl VirtualPageWriter {
let mut indirect1_page =
page_alloc_with_fsm(self.relation, self.flag, self.skip_lock_rel);
indirect1_inode.freespace_mut()[..4]
.copy_from_slice(&data_page.blkno().to_le_bytes());
.copy_from_slice(&indirect1_page.blkno().to_le_bytes());
indirect1_inode.header.pd_lower += 4;
indirect1_page.freespace_mut()[..4]
.copy_from_slice(&data_page.blkno().to_le_bytes());
Expand All @@ -291,7 +300,7 @@ impl VirtualPageWriter {
let inode_space = indirect1_page.freespace_mut();
if inode_space.len() >= 4 {
inode_space[..4].copy_from_slice(&data_page.blkno().to_le_bytes());
indirect1_inode.header.pd_lower += 4;
indirect1_page.header.pd_lower += 4;
*old_data_page = data_page;
return;
}
Expand Down
Loading

0 comments on commit ac59bf8

Please sign in to comment.