الوعي بالرفوف ووضع النسخ عبر مناطق التوافر
تعلّم كيف يوزّع وعي Kafka بالرفوف النسخ المتماثلة عبر الرفوف ومناطق التوافر للبقاء أمام أعطال مراكز البيانات.
الوعي بالرفوف ووضع النسخ عبر مناطق التوافر درس مجاني في Apache Kafka & Stream Processing Fundamentals على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Apache Kafka & Stream Processing Fundamentals، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Apache Kafka & Stream Processing Fundamentals 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
What Is Rack Awareness?
Rack awareness tells Kafka about the physical (or cloud) topology of your brokers.
Without it, all replicas of a partition could land on brokers sharing the same rack or availability zone. If that zone fails, the partition becomes unavailable.
- Each broker advertises a
broker.rackvalue. - Kafka then places replicas on different racks when possible.
Configuring broker.rack
Set broker.rack in each broker's server.properties to identify its rack or zone.
# server.properties on a broker in us-east-1a
broker.id=1
broker.rack=us-east-1a
# Another broker in a different zone
broker.id=2
broker.rack=us-east-1bHow Replicas Get Spread
When a topic is created, Kafka's replica assignment algorithm alternates across racks.
For a partition with replication factor 3 and 3 racks, each replica lands on a distinct rack — guaranteeing the partition survives the loss of any single rack.
Cloud Availability Zones
In AWS, GCP, or Azure, map broker.rack to the availability zone (AZ).
- AZs are physically isolated within a region.
- Spreading replicas across AZs protects against a full AZ outage.
- Beware cross-AZ network costs for replication traffic.
Creating a Rack-Aware Topic
No special flag is needed — if brokers have broker.rack set, topic creation is automatically rack-aware.
kafka-topics.sh --create \
--bootstrap-server localhost:9092 \
--topic orders \
--partitions 6 \
--replication-factor 3Verifying Replica Placement
Use --describe to inspect which brokers hold each replica, then cross-check against broker racks.
kafka-topics.sh --describe \
--bootstrap-server localhost:9092 \
--topic ordersThe min.insync.replicas Tie-In
Rack awareness protects placement, but durability also depends on min.insync.replicas.
With replicas spread across 3 AZs and min.insync.replicas=2, a producer using acks=all can still write even if one entire AZ is down.
Follower Fetching from Closest Replica
Kafka 2.4+ supports fetch from follower. Consumers can read from a replica in their own rack, cutting cross-AZ traffic and latency.
# broker config
replica.selector.class=org.apache.kafka.common.replica.RackAwareReplicaSelector
# consumer config
client.rack=us-east-1aLimitations to Know
Rack awareness is best-effort:
- If racks < replication factor, some replicas share a rack.
- Reassignments triggered manually do not always respect racks unless you generate a rack-aware plan.
- It does not rebalance existing topics when you add
broker.racklater.
Generating a Rack-Aware Reassignment
To fix existing topics after enabling rack awareness, generate a reassignment plan with the reassign-partitions tool.
kafka-reassign-partitions.sh \
--bootstrap-server localhost:9092 \
--topics-to-move-json-file topics.json \
--broker-list 1,2,3 \
--generateDesign Checklist
Before going to production:
- Replication factor >= number of racks you want to tolerate losing + 1.
- Set
min.insync.replicasto at least 2. - Use
acks=allon critical producers. - Enable follower fetching to control cross-AZ costs.
Quick Check
Test your understanding of rack awareness.
Recap
You learned how rack awareness spreads replicas across racks and availability zones.
- Set
broker.rackper broker. - Topic creation becomes automatically rack-aware.
- Combine with
min.insync.replicasandacks=allfor AZ-failure resilience. - Use follower fetching to reduce cross-AZ cost.
الأسئلة الشائعة
هل درس «الوعي بالرفوف ووضع النسخ عبر مناطق التوافر» مجاني؟
نعم — نص درس «الوعي بالرفوف ووضع النسخ عبر مناطق التوافر» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Apache Kafka & Stream Processing Fundamentals، انتقل إلى CoddyKit PRO. تتضمن دورة Apache Kafka & Stream Processing Fundamentals 4 دروس في المجموع.
ماذا ستتعلم في «الوعي بالرفوف ووضع النسخ عبر مناطق التوافر»؟
تعلّم كيف يوزّع وعي Kafka بالرفوف النسخ المتماثلة عبر الرفوف ومناطق التوافر للبقاء أمام أعطال مراكز البيانات. تتمرن على Apache Kafka & Stream Processing Fundamentals مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Apache Kafka & Stream Processing Fundamentals؟
لا تُشترط خبرة سابقة. Apache Kafka & Stream Processing Fundamentals على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «الوعي بالرفوف ووضع النسخ عبر مناطق التوافر»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Apache Kafka & Stream Processing Fundamentals هذا؟
نعم. كل درس في Apache Kafka & Stream Processing Fundamentals يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- التكرار وتحمل الأعطال
- أدوار Controller وZooKeeper/Kraft
- تصميم عنقود Kafka
- الوعي بالرفوف ووضع النسخ عبر مناطق التوافر