Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of ClusterInfoBuilder #1165

Merged
merged 7 commits into from
Nov 28, 2022

Conversation

garyparrot
Copy link
Collaborator

@garyparrot garyparrot commented Nov 23, 2022

Context: #1157

實作一些物件能夠方便我們從無生出一個 ClusterInfo

  • 實作 ClusterInfoBuilder,可以對空或是給定的 ClusterInfo 做出轉變。

Demo

public class Ignore {

  public static void main(String[] args) {
    ClusterInfo<Replica> pipeline =
        ClusterInfoBuilder.builder()
            .addNode(1, 2, 3)
            .addFolders(1, "/ssd1", "/ssd2", "/ssd3")
            .addFolders(2, "/ssd1", "/ssd2", "/ssd3")
            .addFolders(3, "/ssd1", "/ssd2", "/ssd3")
            .addTopic("empty", 3, (short) 3)
            .addTopic("heavy", 5, (short) 1, r -> Replica.builder(r).size(1_000_000_000).build())
            .mapLog(
                r -> !r.topic().equals("empty") && ThreadLocalRandom.current().nextInt() % 2 == 0,
                r -> Replica.builder(r).isOffline(true).build())
            .build();

    pipeline.nodes().forEach(System.out::println);
    pipeline.replicas().forEach(System.out::println);
    pipeline.replicas().stream().map(Replica::size).forEach(System.out::println);
  }
}
FakeNodeInfo{host=fake-node-2, id=2, port=9337}
FakeNodeInfo{host=fake-node-1, id=1, port=17748}
FakeNodeInfo{host=fake-node-3, id=3, port=16329}
Replica{topic='empty', partition=0, broker=FakeNodeInfo{host=fake-node-2, id=2, port=9337}, path='/ssd1', leader=true}
Replica{topic='empty', partition=0, broker=FakeNodeInfo{host=fake-node-1, id=1, port=17748}, path='/ssd1', leader=false}
Replica{topic='empty', partition=0, broker=FakeNodeInfo{host=fake-node-3, id=3, port=16329}, path='/ssd1', leader=false}
Replica{topic='empty', partition=1, broker=FakeNodeInfo{host=fake-node-2, id=2, port=9337}, path='/ssd2', leader=true}
Replica{topic='empty', partition=1, broker=FakeNodeInfo{host=fake-node-1, id=1, port=17748}, path='/ssd2', leader=false}
Replica{topic='empty', partition=1, broker=FakeNodeInfo{host=fake-node-3, id=3, port=16329}, path='/ssd2', leader=false}
Replica{topic='empty', partition=2, broker=FakeNodeInfo{host=fake-node-2, id=2, port=9337}, path='/ssd3', leader=true}
Replica{topic='empty', partition=2, broker=FakeNodeInfo{host=fake-node-1, id=1, port=17748}, path='/ssd3', leader=false}
Replica{topic='empty', partition=2, broker=FakeNodeInfo{host=fake-node-3, id=3, port=16329}, path='/ssd3', leader=false}
Replica{topic='heavy', partition=0, broker=FakeNodeInfo{host=fake-node-2, id=2, port=9337}, path='/ssd1', leader=true}
Replica{topic='heavy', partition=1, broker=FakeNodeInfo{host=fake-node-1, id=1, port=17748}, path='/ssd1', leader=true}
Replica{topic='heavy', partition=2, broker=FakeNodeInfo{host=fake-node-3, id=3, port=16329}, path='/ssd1', leader=true}
Replica{topic='heavy', partition=3, broker=FakeNodeInfo{host=fake-node-2, id=2, port=9337}, path='/ssd2', leader=true}
Replica{topic='heavy', partition=4, broker=FakeNodeInfo{host=fake-node-1, id=1, port=17748}, path='/ssd2', leader=true}
0
0
0
0
0
0
0
0
0
1000000000
1000000000
10000000000
10000000000
1000000000

為避免 PR 臃腫,關於 ClusterLogAllocation 的整合會在其他 PR 完成。

A series of function for changing the cluster info
@garyparrot garyparrot self-assigned this Nov 23, 2022
@garyparrot
Copy link
Collaborator Author

測試之後會補上

@garyparrot garyparrot changed the title implementation of ClusterInfoAlteration Implementation of ClusterInfoAlteration Nov 23, 2022
@garyparrot garyparrot changed the title Implementation of ClusterInfoAlteration Implementation of ClusterInfoBuilder Nov 26, 2022
Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garyparrot 這是一個很有用的工具,不過如同前面很多次討論工具時的話題,要避免程式碼寫到發散,也就是少了一個設計的”核心“,變成想到什麼就寫什麼,下面我留了幾個討論,麻煩看一下

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants