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

Refactor source file structure #989

Merged
merged 5 commits into from
Oct 17, 2022

Conversation

PragmaTwice
Copy link
Member

Mostly follows #977 (comment), except:

  • log_collector and tls_util is moved to network/
  • add task_runner to common/

@PragmaTwice
Copy link
Member Author

log_collector is not a network thing, and i think it should be put under common

I think both common and network is ok, I put it into network because I find that this file relies on redis_reply and is using redis protocol. I will move it to common.

@caipengbo
Copy link
Contributor

@PragmaTwice log_collector is not a network-related thing, it is a statistical thing, how about adding a stats directory with log_collector.h and stats.h or even redis_disk.h (or can rename it disk_stats.h?)

@PragmaTwice
Copy link
Member Author

@PragmaTwice log_collector is not a network-related thing, it is a statistical thing, how about adding a stats directory with log_collector.h and stats.h or even redis_disk.h (or can rename it disk_stats.h?)

Greate idea. I will do it.

@caipengbo
Copy link
Contributor

geohash.h file appears to be used only by redis_geo.h. I don't think it's appropriate to put it in storage. Can we just put it inside types?

@PragmaTwice
Copy link
Member Author

geohash.h file appears to be used only by redis_geo.h. I don't think it's appropriate to put it in storage. Can we just put it inside types?

Agree with that.

@caipengbo
Copy link
Contributor

log_collector is not a network-related thing, it is a statistical thing, how about adding a stats directory with log_collector.h and stats.h or even redis_disk.h (or can rename it disk_stats.h?)

We renamed redis_disk.h to disk_stats.h, do you think that is reasonable? @tanruixiang

@PragmaTwice
Copy link
Member Author

Current source structure:

$ tree src
├── cluster
│   ├── cluster.cc
│   ├── cluster.h
│   ├── redis_slot.cc
│   ├── redis_slot.h
│   ├── replication.cc
│   ├── replication.h
│   ├── slot_import.cc
│   ├── slot_import.h
│   ├── slot_migrate.cc
│   └── slot_migrate.h
├── commands
│   ├── redis_cmd.cc
│   └── redis_cmd.h
├── common
│   ├── cron.cc
│   ├── cron.h
│   ├── db_util.h
│   ├── encoding.cc
│   ├── encoding.h
│   ├── event_util.h
│   ├── fd_util.h
│   ├── parse_util.h
│   ├── rand.cc
│   ├── rand.h
│   ├── rocksdb_crc32c.h
│   ├── rw_lock.h
│   ├── scope_exit.h
│   ├── sha1.cc
│   ├── sha1.h
│   ├── status.h
│   ├── task_runner.cc
│   ├── task_runner.h
│   ├── util.cc
│   └── util.h
├── config
│   ├── config.cc
│   ├── config.h
│   ├── config_type.h
│   ├── config_util.cc
│   └── config_util.h
├── main.cc
├── network
│   ├── redis_connection.cc
│   ├── redis_connection.h
│   ├── redis_reply.cc
│   ├── redis_reply.h
│   ├── redis_request.cc
│   ├── redis_request.h
│   ├── server.cc
│   ├── server.h
│   ├── tls_util.cc
│   ├── tls_util.h
│   ├── worker.cc
│   └── worker.h
├── stats
│   ├── disk_stats.cc
│   ├── disk_stats.h
│   ├── log_collector.cc
│   ├── log_collector.h
│   ├── stats.cc
│   └── stats.h
├── storage
│   ├── batch_extractor.cc
│   ├── batch_extractor.h
│   ├── compact_filter.cc
│   ├── compact_filter.h
│   ├── compaction_checker.cc
│   ├── compaction_checker.h
│   ├── event_listener.cc
│   ├── event_listener.h
│   ├── lock_manager.cc
│   ├── lock_manager.h
│   ├── redis_db.cc
│   ├── redis_db.h
│   ├── redis_metadata.cc
│   ├── redis_metadata.h
│   ├── redis_pubsub.cc
│   ├── redis_pubsub.h
│   ├── scripting.cc
│   ├── scripting.h
│   ├── storage.cc
│   ├── storage.h
│   ├── table_properties_collector.cc
│   └── table_properties_collector.h
├── types
│   ├── geohash.cc
│   ├── geohash.h
│   ├── redis_bitmap.cc
│   ├── redis_bitmap.h
│   ├── redis_bitmap_string.cc
│   ├── redis_bitmap_string.h
│   ├── redis_geo.cc
│   ├── redis_geo.h
│   ├── redis_hash.cc
│   ├── redis_hash.h
│   ├── redis_list.cc
│   ├── redis_list.h
│   ├── redis_set.cc
│   ├── redis_set.h
│   ├── redis_sortedint.cc
│   ├── redis_sortedint.h
│   ├── redis_stream_base.cc
│   ├── redis_stream_base.h
│   ├── redis_stream.cc
│   ├── redis_stream.h
│   ├── redis_string.cc
│   ├── redis_string.h
│   ├── redis_zset.cc
│   └── redis_zset.h
├── valgrind.sup
└── version.h.in

8 directories, 104 files

@PragmaTwice PragmaTwice linked an issue Oct 14, 2022 that may be closed by this pull request
2 tasks
Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

Great work! Comments inline.

@@ -148,12 +148,12 @@ find_library(FOUND_UNWIND_LIB unwind)
set(WARNING_FLAGS -Wall -Wpedantic -Wsign-compare -Wreturn-type)

# kvrocks objects target
file(GLOB KVROCKS_SRCS src/*.cc)
file(GLOB_RECURSE KVROCKS_SRCS src/*.cc)
Copy link
Member

Choose a reason for hiding this comment

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

Does the build benefit from separating compile units? For example, one .o per directory and for better incremental compilation. If it does we can implement it here or as a follow-up.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think there is not much dependency between translation units. In theory, if there are 1000 source files, a 1000-core cpu and enough memory, we can compile completely in parallel.

list(FILTER KVROCKS_SRCS EXCLUDE REGEX src/main.cc)

add_library(kvrocks_objs OBJECT ${KVROCKS_SRCS})

target_include_directories(kvrocks_objs PUBLIC src ${PROJECT_BINARY_DIR})
target_include_directories(kvrocks_objs PUBLIC src src/common ${PROJECT_BINARY_DIR})
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason of this change?

Copy link
Member Author

@PragmaTwice PragmaTwice Oct 14, 2022

Choose a reason for hiding this comment

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

Since header files in common is frequently used, so e.g. it can be just "status.h" rather than "common/status.h".

src/cluster/cluster.cc Show resolved Hide resolved
@tanruixiang
Copy link
Member

We renamed redis_disk.h to disk_stats.h, do you think that is reasonable? @tanruixiang

Yes, I think it's reasonable.

@git-hulk
Copy link
Member

@PragmaTwice After looking detail, it seems server is better than network to replace service. It's my bad that didn't mention this option, others are good to me. I think we can merge it as soon as possible to avoid conflicts.

@PragmaTwice
Copy link
Member Author

PragmaTwice commented Oct 15, 2022

@PragmaTwice After looking detail, it seems server is better than network to replace service. It's my bad that didn't mention this option, others are good to me. I think we can merge it as soon as possible to avoid conflicts.

Done. @git-hulk

The current diff in github review page seems to be a mess, maybe because I rebase some commits.

@PragmaTwice
Copy link
Member Author

PragmaTwice commented Oct 15, 2022

The current diff in github review page seems to be a mess, maybe because I rebase some commits.

Solved by re-rebase and force-push.

Current source structure:

src
├── cluster
│   ├── cluster.cc
│   ├── cluster.h
│   ├── redis_slot.cc
│   ├── redis_slot.h
│   ├── replication.cc
│   ├── replication.h
│   ├── slot_import.cc
│   ├── slot_import.h
│   ├── slot_migrate.cc
│   └── slot_migrate.h
├── commands
│   ├── redis_cmd.cc
│   └── redis_cmd.h
├── common
│   ├── cron.cc
│   ├── cron.h
│   ├── db_util.h
│   ├── encoding.cc
│   ├── encoding.h
│   ├── event_util.h
│   ├── fd_util.h
│   ├── parse_util.h
│   ├── rand.cc
│   ├── rand.h
│   ├── rocksdb_crc32c.h
│   ├── rw_lock.h
│   ├── scope_exit.h
│   ├── sha1.cc
│   ├── sha1.h
│   ├── status.h
│   ├── task_runner.cc
│   ├── task_runner.h
│   ├── util.cc
│   └── util.h
├── config
│   ├── config.cc
│   ├── config.h
│   ├── config_type.h
│   ├── config_util.cc
│   └── config_util.h
├── main.cc
├── server
│   ├── redis_connection.cc
│   ├── redis_connection.h
│   ├── redis_reply.cc
│   ├── redis_reply.h
│   ├── redis_request.cc
│   ├── redis_request.h
│   ├── server.cc
│   ├── server.h
│   ├── tls_util.cc
│   ├── tls_util.h
│   ├── worker.cc
│   └── worker.h
├── stats
│   ├── disk_stats.cc
│   ├── disk_stats.h
│   ├── log_collector.cc
│   ├── log_collector.h
│   ├── stats.cc
│   └── stats.h
├── storage
│   ├── batch_extractor.cc
│   ├── batch_extractor.h
│   ├── compact_filter.cc
│   ├── compact_filter.h
│   ├── compaction_checker.cc
│   ├── compaction_checker.h
│   ├── event_listener.cc
│   ├── event_listener.h
│   ├── lock_manager.cc
│   ├── lock_manager.h
│   ├── redis_db.cc
│   ├── redis_db.h
│   ├── redis_metadata.cc
│   ├── redis_metadata.h
│   ├── redis_pubsub.cc
│   ├── redis_pubsub.h
│   ├── scripting.cc
│   ├── scripting.h
│   ├── storage.cc
│   ├── storage.h
│   ├── table_properties_collector.cc
│   └── table_properties_collector.h
├── types
│   ├── geohash.cc
│   ├── geohash.h
│   ├── redis_bitmap.cc
│   ├── redis_bitmap.h
│   ├── redis_bitmap_string.cc
│   ├── redis_bitmap_string.h
│   ├── redis_geo.cc
│   ├── redis_geo.h
│   ├── redis_hash.cc
│   ├── redis_hash.h
│   ├── redis_list.cc
│   ├── redis_list.h
│   ├── redis_set.cc
│   ├── redis_set.h
│   ├── redis_sortedint.cc
│   ├── redis_sortedint.h
│   ├── redis_stream_base.cc
│   ├── redis_stream_base.h
│   ├── redis_stream.cc
│   ├── redis_stream.h
│   ├── redis_string.cc
│   ├── redis_string.h
│   ├── redis_zset.cc
│   └── redis_zset.h
├── valgrind.sup
└── version.h.in

8 directories, 104 files

git-hulk
git-hulk previously approved these changes Oct 15, 2022
tisonkun
tisonkun previously approved these changes Oct 15, 2022
torwig
torwig previously approved these changes Oct 15, 2022
Copy link
Contributor

@torwig torwig left a comment

Choose a reason for hiding this comment

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

@PragmaTwice Good job!
LGTM (with or without src/common among include directories)

@tisonkun
Copy link
Member

@PragmaTwice please rebase on the latest unstable branch.

@ShooterIT @caipengbo could you give a review on this patch? Perhaps we should move it forward in a timely manner to avoid further conflicts.

caipengbo
caipengbo previously approved these changes Oct 16, 2022
Copy link
Contributor

@caipengbo caipengbo left a comment

Choose a reason for hiding this comment

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

LGTM

@PragmaTwice
Copy link
Member Author

@PragmaTwice please rebase on the latest unstable branch.

Done.

@tisonkun tisonkun merged commit 17d5fd7 into apache:unstable Oct 17, 2022
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.

Proposal: Refactor source file structure
6 participants